Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] Qt beginner question: findNext and findPrevious "identifier not found"
This is my first post here, apologies for formatting mistakes or similar things. I'm trying to compile and run one of the first examples from the book "C++ GUI Programming with Qt 4". I'm using an up-to-date Qt Creator 2.7.0, based on Qt 5.0.2 (32 bit), all running on a Windows 8 (shame on me) machine. Everything is out of a fresh install; my understanding is that it should work fine without further configuration, although I have some doubts. Simpler Qt applications (previous examples in the book) run fine in this configuration.
I tried Build->Clean All, Build->Run qmake, Build->Build Project. I initially got many errors as apparently "#include<QtGui>" didn't work as intended; but I could solve most errors by including all the relevant classes. I have two errors left:
@error: C3861: 'findPrevious': identifier not found
error: C3861: 'findNext': identifier not found@
If I comment out the lines producing the error, the program compiles, but crashes:
The program has unexpectedly finished.
C:\Qt\Qt502\Tools\QtCreator\bin\build-QtTest-Desktop_Qt_5_0_2_MSVC2012_64bit-Debug\debug\QtTest exited with code -1073741819@
The complete code should be identical to that in the book (except I used "testdialog" instead of "finddialog" and had to add a bunch of includes), and is as follows:
int main(int argc, char *argv)
QApplication a(argc, argv);
TestDialog *dialog = new TestDialog(0);
class TestDialog : public QDialog
//Provides ~events/delegates (SIGNALS/SLOTS) with qmake.
explicit TestDialog(QWidget *parent = 0);
void enableTestButton(const QString &text);
#endif // TESTDIALOG_H
#include <QtGui> //Doesn't seem to work. I get errors for basically every class. Had to "manually" include each class.
TestDialog::TestDialog(QWidget *parent) :
label = new QLabel(tr("Find &what:"));
caseCheckBox = new QCheckBox(tr("Match &case"));
backwardCheckBox = new QCheckBox(tr("Search &backward"));
testButton = new QPushButton(tr("&Find")); testButton->setDefault(true); testButton->setEnabled(false); closeButton = new QPushButton(tr("Close")); connect(lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableFindButton(const Qstring &))); connect(testButton, SIGNAL(clicked(const QString &)), this, SLOT(findClicked())); connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *topLeftLayout = new QHBoxLayout(); topLeftLayout->addWidget(label); topLeftLayout->addWidget(lineEdit); QVBoxLayout *leftLayout = new QVBoxLayout(); leftLayout->addLayout(topLeftLayout); leftLayout->addWidget(caseCheckBox); leftLayout->addWidget(backwardCheckBox); QVBoxLayout *rightLayout = new QVBoxLayout(); rightLayout->addWidget(testButton); rightLayout->addWidget(closeButton); rightLayout->addStretch(); QHBoxLayout *mainLayout = new QHBoxLayout(); mainLayout->addLayout(leftLayout); mainLayout->addLayout(rightLayout); setLayout(mainLayout); setWindowTitle(tr("Find")); setFixedHeight(sizeHint().height());
QString text = lineEdit->text();
Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
emit findPrevious(text, cs); //error 1
emit findNext(text, cs); //error 2
void TestDialog::enableTestButton(const QString &text)
Thanks in advance.
You didn't declare findPrevious nor findNext in your signals.
And since you're on Qt5 with code from Qt4 did you add
@QT += widgets@
To your pro file ?
Hope it helps
I feel stupid for missing the signals declaration; I just assumed that somehow these specific signals were included in Qt. The program now compiles fine, although it still crashes once compiled. I'll look into why it crashes before I call this "solved", might be something as simple as what you just mentioned. Thanks!
I would say: lineEdit not initialized before you use it
@SGaist: yeah, I actually figured it out on my own. So as expected, another stupid mistake, and here I was trying to figure out if the Qt installation was messed up... Anyway, thanks! Solved.
Your welcome !
Don't forget the debugger, he's (almost) always your friend :)