问题是标题所示.O得到错误:期望的类型标识符,(我认为)来自在类型声明之前读取的函数声明.
type
TForm1 = class(TForm)
//other declarations
function ItemThere(x: TItem): boolean; // here it says TItem is unknown
end;
type
TItem = class
Name : String;
Description : String;
constructor Create;
end;
Run Code Online (Sandbox Code Playgroud)
另外,我想让你知道我是一个相当缺乏经验的程序员.我怎样才能解决这个问题?我应该将TItem的声明移到TForm1之上吗?谢谢您的帮助.
我正在编写一个程序,创建一个QLineEdit,该QLineEdit仅接受数字,并且在拒绝非数字的输入时应将背景变为任意颜色。如果输入有效,它将再次使背景变白。现在,我需要将QLineEdit的inputRejected和textEdited事件分别连接到randomcolor()和white(),但是连接使我很麻烦,而且我不知道如何解决它。
这是我第一次使用连接,并且我在许多论坛上摸索着尝试在这里找到的不同语法。
#include <QtWidgets>
class OnlyNumbers : QLineEdit {
public:
static int spawn(int argc, char *argv[]){
QApplication app(argc, argv);
OnlyNumbers P;
return app.exec();
}
OnlyNumbers() : QLineEdit() {
this->setValidator(new QIntValidator());
QObject::connect(this, SIGNAL(inputRejected()), this, SLOT(randomcolor()));
QObject::connect(this, SIGNAL(&QLineEdit::textEdited(const QString)), this, SLOT(&OnlyNumbers::white()));
QRegExp rx("[0-9]*"); QValidator *validator = new QRegExpValidator(rx, this);
this->setValidator(validator);
this->show();
}
public slots:
void randomcolor(){
this->setStyleSheet("QLineEdit { background: rgb(std::rand()%256, rand()%256, rand()%256); selection-background-color: rgb(rand()%256, rand()%256, rand()%256); }");
}
void white(){
this->setStyleSheet("QLineEdit { background: rgb(255, 255, 255); selection-background-color: rgb(233, 99, 0); }");
} …Run Code Online (Sandbox Code Playgroud)