Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Need help in Qt example
QtWS25 Last Chance

Need help in Qt example

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    doforumda
    wrote on last edited by
    #1

    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
    finddialog.h

    @#ifndef FINDDIALOG_H #define FINDDIALOG_H
    #include <QDialog>
    class QCheckBox;
    class QLabel;
    class QlineEdit;
    class QPushButton;
    class FindDialog : public QDialog
    {
    Q_OBJECT;
    public:
    FindDialog(QWidget *parent = 0);
    signals:
    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);
    private:
    QLabel *label;
    QLineEdit *lineEdit;
    QCheckBox *caseCheckBox;
    QCheckBox *backwardCheckBox;
    QPushButton *findButton;
    QPushButton *closeButton;
    };
    #endif@

    finddialog.cpp

    @#include <QtGui> #include "finddialog.h";
    FindDialog::FindDialog(QWidget *parent)
    :QDialog(parent)
    {
    label = new QLabel(tr("Find &what:"));
    lineEdit = new QLineEdit;
    label->setBuddy(lineEdit);
    caseCheckBox = new QCheckBox(tr("Match &case"));
    backwardCheckBox = new QCheckBox(tr("Search &backward"));
    findButton = new QPushButton(tr("&Find"));
    findButton->setDefault(true);
    findButton->setEnabled(false);
    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;
    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(findButton);
    rightLayout->addWidget(closeButton);
    rightLayout->addStretch();
    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addLayout(leftLayout);
    mainLayout->addLayout(rightLayout);
    setLayout(mainLayout);
    setWindowTitle(tr("Find"));
    setFixedHeight(sizeHint().height());
    }
    void FindDialog::findClicked()
    {
    QString text = lineEdit->text();
    QtCaseSensitivity cs =
    caseCheckBox->isChecked() ? Qt::CaseSensitive
    : Qt::CaseInsensitive;
    if(backwardCheckBox->isChecked())
    {
    emit findPrevious(text, cs);
    }
    else {
    emit findNext(text, cs);
    }
    }
    void FindDialog::enableFindButton(const QString &text)
    {
    findButton->setEnabled(!text.isEmpty());
    }@

    main.cpp

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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      anselmolsm
      wrote on last edited by
      #2

      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()@

      Anselmo L. S. Melo (anselmolsm)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        doforumda
        wrote on last edited by
        #3

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

        once again thanks

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            doforumda
            wrote on last edited by
            #5

            thanks for this information

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

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #6

              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":http://doc.trolltech.com/4.6/how-to-learn-qt.html is also pretty helpful.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cyberbobs
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved