Important: Please read the Qt Code of Conduct -

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

    mingw32-make: Entering directory `C:/Qt/2010.04/examples/find-build-desktop'

    C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug

    mingw32-make[1]: Entering directory `C:/Qt/2010.04/examples/find-build-desktop'

    c:\Qt\2010.04\qt\bin\uic.exe ..\find\finddialog.ui -o ui_finddialog.h

    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[1]: Leaving directory `C:/Qt/2010.04/examples/find-build-desktop'

    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

    @#ifndef FINDDIALOG_H #define FINDDIALOG_H
    #include <QDialog>
    class QCheckBox;
    class QLabel;
    class QlineEdit;
    class QPushButton;
    class FindDialog : public QDialog
    FindDialog(QWidget *parent = 0);
    void findNext(const QString &str, Qt::CaseSensitivity cs);
    void findPrevious(const QString &str, Qt::CaseSensitivity cs);
    private slots:
    void findClicked();
    void enableFindButton(const QString &text);
    QLabel *label;
    QLineEdit *lineEdit;
    QCheckBox *caseCheckBox;
    QCheckBox *backwardCheckBox;
    QPushButton *findButton;
    QPushButton *closeButton;


    @#include <QtGui> #include "finddialog.h";
    FindDialog::FindDialog(QWidget *parent)
    label = new QLabel(tr("Find &what:"));
    lineEdit = new QLineEdit;
    caseCheckBox = new QCheckBox(tr("Match &case"));
    backwardCheckBox = new QCheckBox(tr("Search &backward"));
    findButton = new QPushButton(tr("&Find"));
    closeButton = new QPushButton(tr("Close"));
    connect(lineEdit, SIGNAL(textChanged(const QString &)),
    this, SLOT(enableFindButton(const QString &)));
    connect(findButton, SIGNAL(clicked()),
    this, SLOT(findClicked()));
    connect(closeButton, SIGNAL(clicked()),
    this, SLOT(close()));
    QHBoxLayout *topLeftLayout = new QHBoxLayout;
    QVBoxLayout *leftLayout = new QVBoxLayout;
    QVBoxLayout *rightLayout = new QVBoxLayout;
    QHBoxLayout *mainLayout = new QHBoxLayout;
    void FindDialog::findClicked()
    QString text = lineEdit->text();
    QtCaseSensitivity cs =
    caseCheckBox->isChecked() ? Qt::CaseSensitive
    : Qt::CaseInsensitive;
    emit findPrevious(text, cs);
    else {
    emit findNext(text, cs);
    void FindDialog::enableFindButton(const QString &text)


    @#include <QtGui/QApplication> #include "finddialog.h"
    int main(int argc, char *argv[])
    QApplication app(argc, argv);
    FindDialog *dialog = new FindDialog;;
    return app.exec();

  • 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 @Qt::CaseSensitivity@ instead of @QtCaseSensitivity@

    in file finddialog.h:

    • line 05: the correct is : @QLineEdit@

    in file main.cpp:

    • line 06: @dialog->show()@

  • anselmolsm you are brilliant. thanks alot man. can you please tell me which is the best place to Qt.

    once again thanks

  • Moderators

    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:-)

  • thanks for this information

    can you please tell me which is the best place to learn Qt.

  • Moderators

    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": is also pretty helpful.

  • Well, the "C++ GUI Programming with Qt4" book was quite useful for me.

    It wouldn't give you an information about the most fresh and intresting thing that appeared in Qt in the last two years, but it is definitely a good point to start learning the basics.

Log in to reply