need help in Qt example
hi
i have a problem in one of Qt example. I am following C++ GUI Programming with Qt, Second Edition and Using Qt Creator. I copy an example from this book but it is not working and showing error this error to me
- Starting: "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" -w
- C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug
- mingw32-make[1]: Entering directory `C:/Qt/2010.04/examples/find-build-desktop'
- g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\qt\include\QtCore" -I"..\..\qt\include\QtGui" -I"..\..\qt\include" -I"..\..\qt\include\ActiveQt" -I"debug" -I"." -I"..\find" -I"." -I"..\..\qt\mkspecs\win32-g++" -o debug\main.o ..\find\main.cpp
- mingw32-make: Leaving directory `C:/Qt/2010.04/examples/find-build-desktop'
- mingw32-make[1]: *** [debug/main.o] Error 1
- mingw32-make: *** [debug] Error 2
- The process "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited with code %2.
- Error while building project find (target: Desktop)
- When executing build step 'Make'
here is my code
finddialog.h
- #ifndef FINDDIALOG_H #define FINDDIALOG_H
- #include <QDialog>
- class QCheckBox;
- class QLabel;
- class QlineEdit;
- class QPushButton;
- {
- Q_OBJECT;
- public:
- signals:
- private slots:
- void findClicked();
- private:
- };
- #endif
finddialog.cpp
- #include <QtGui> #include "finddialog.h";
- {
- lineEdit = new QLineEdit;
- label->setBuddy(lineEdit);
- findButton->setDefault(true);
- findButton->setEnabled(false);
- connect(findButton, SIGNAL(clicked()),
- this, SLOT(findClicked()));
- connect(closeButton, SIGNAL(clicked()),
- this, SLOT(close()));
- topLeftLayout->addWidget(label);
- topLeftLayout->addWidget(lineEdit);
- leftLayout->addLayout(topLeftLayout);
- leftLayout->addWidget(caseCheckBox);
- leftLayout->addWidget(backwardCheckBox);
- rightLayout->addWidget(findButton);
- rightLayout->addWidget(closeButton);
- rightLayout->addStretch();
- mainLayout->addLayout(leftLayout);
- mainLayout->addLayout(rightLayout);
- setLayout(mainLayout);
- setWindowTitle(tr("Find"));
- setFixedHeight(sizeHint().height());
- }
- void FindDialog::findClicked()
- {
- QtCaseSensitivity cs =
- if(backwardCheckBox->isChecked())
- {
- emit findPrevious(text, cs);
- }
- else {
- emit findNext(text, cs);
- }
- }
- {
- findButton->setEnabled(!text.isEmpty());
- }
main.cpp
- #include <QtGui/QApplication> #include "finddialog.h"
- int main(int argc, char *argv[])
- {
- FindDialog *dialog = new FindDialog;
- dialog.show();
- return app.exec();
- }
6 replies
In finddialog.cpp:
- line 01: Remove the semicolon (;) in the end of the include statement. Also, I suggest you to put one include per line
- line 41: Maybe it is wrong due to a wiki rendering bug, should be instead of
- QtCaseSensitivity
in file finddialog.h:
- line 05: the correct is :
in file main.cpp:
- line 06:
- dialog->show()
All preprocessor directives (all the lines starting with #) need to have the # at the first column. You may have spaces right after the # character. This makes it necessary to put each preprocessor directive onto its own line!
What is a preprocessor directive?
Well, early programming languages had quite a few limitations, so programmers went around them by running their code through a preprocessor before passing it on to the actual compiler. The preprocessor used by C (and in extension C++) is called cpp and basically treats all lines starting with # as instructions for itself. It is pretty powerful, able to insert files in place of a line (#include), it allows to define macros which are then searched and replaced in the text (#define), quite a bit of logic to remove lines from the input stream (#if etc.). It further treats line continuations (concatenating a line that ends with ‘\’ with the following line), removes comments, and does obscure stuff like replacing some sequences of letters with others (needed back then when some terminals had no ‘{’ etc.).
Actually cpp is quite a powerful beast, even though (thankfully) mostly reduced to #include stuff nowadays:-)
I went through the tutorials back when I learned Qt, but I already had a very strong background in C++.
In general I think the documentation and tutorials available with Qt are really good. But I personally prefer reading a book to get into any new topic (call me old-fashioned;-).
This page [doc.trolltech.com] is also pretty helpful.
You must log in to post a reply. Not a member yet? Register here!





