July 11, 2010

doforumda doforumda
Lab Rat
161 posts

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

  1. Starting: "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" -w
  2.  
  3. mingw32-make: Entering directory `C:/Qt/2010.04/examples/find-build-desktop'
  4.  
  5. C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug
  6.  
  7. mingw32-make[1]: Entering directory `C:/Qt/2010.04/examples/find-build-desktop'
  8.  
  9. c:\Qt\2010.04\qt\bin\uic.exe ..\find\finddialog.ui -o ui_finddialog.h
  10.  
  11. 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
  12.  
  13. mingw32-make[1]: Leaving directory `C:/Qt/2010.04/examples/find-build-desktop'
  14.  
  15. mingw32-make: Leaving directory `C:/Qt/2010.04/examples/find-build-desktop'
  16.  
  17. mingw32-make[1]: *** [debug/main.o] Error 1
  18.  
  19. mingw32-make: *** [debug] Error 2
  20.  
  21. The process "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited with code %2.
  22.  
  23. Error while building project find (target: Desktop)
  24.  
  25. When executing build step 'Make'

here is my code
finddialog.h

  1. #ifndef FINDDIALOG_H #define FINDDIALOG_H
  2.   #include <QDialog>
  3.   class QCheckBox;
  4.  class QLabel;
  5.  class QlineEdit;
  6.  class QPushButton;
  7.   class FindDialog : public QDialog
  8.  {
  9.      Q_OBJECT;
  10.   public:
  11.      FindDialog(QWidget *parent = 0);
  12.   signals:
  13.      void findNext(const QString &str, Qt::CaseSensitivity cs);
  14.      void findPrevious(const QString &str, Qt::CaseSensitivity cs);
  15.   private slots:
  16.      void findClicked();
  17.      void enableFindButton(const QString &text);
  18.   private:
  19.      QLabel *label;
  20.      QLineEdit *lineEdit;
  21.      QCheckBox *caseCheckBox;
  22.      QCheckBox *backwardCheckBox;
  23.      QPushButton *findButton;
  24.      QPushButton *closeButton;
  25.  };
  26.   #endif

finddialog.cpp

  1. #include <QtGui> #include "finddialog.h";
  2.   FindDialog::FindDialog(QWidget *parent)
  3.      :QDialog(parent)
  4.  {
  5.      label = new QLabel(tr("Find &what:"));
  6.      lineEdit = new QLineEdit;
  7.      label->setBuddy(lineEdit);
  8.       caseCheckBox = new QCheckBox(tr("Match &case"));
  9.      backwardCheckBox = new QCheckBox(tr("Search &backward"));
  10.       findButton = new QPushButton(tr("&Find"));
  11.      findButton->setDefault(true);
  12.      findButton->setEnabled(false);
  13.       closeButton = new QPushButton(tr("Close"));
  14.       connect(lineEdit, SIGNAL(textChanged(const QString &)),
  15.              this, SLOT(enableFindButton(const QString &)));
  16.      connect(findButton, SIGNAL(clicked()),
  17.              this, SLOT(findClicked()));
  18.      connect(closeButton, SIGNAL(clicked()),
  19.              this, SLOT(close()));
  20.       QHBoxLayout *topLeftLayout = new QHBoxLayout;
  21.      topLeftLayout->addWidget(label);
  22.      topLeftLayout->addWidget(lineEdit);
  23.       QVBoxLayout *leftLayout = new QVBoxLayout;
  24.      leftLayout->addLayout(topLeftLayout);
  25.      leftLayout->addWidget(caseCheckBox);
  26.      leftLayout->addWidget(backwardCheckBox);
  27.       QVBoxLayout *rightLayout = new QVBoxLayout;
  28.      rightLayout->addWidget(findButton);
  29.      rightLayout->addWidget(closeButton);
  30.      rightLayout->addStretch();
  31.       QHBoxLayout *mainLayout = new QHBoxLayout;
  32.      mainLayout->addLayout(leftLayout);
  33.      mainLayout->addLayout(rightLayout);
  34.      setLayout(mainLayout);
  35.       setWindowTitle(tr("Find"));
  36.      setFixedHeight(sizeHint().height());
  37.  }
  38.   void FindDialog::findClicked()
  39.  {
  40.      QString text = lineEdit->text();
  41.      QtCaseSensitivity cs =
  42.              caseCheckBox->isChecked() ? Qt::CaseSensitive
  43.                                        : Qt::CaseInsensitive;
  44.      if(backwardCheckBox->isChecked())
  45.      {
  46.          emit findPrevious(text, cs);
  47.      }
  48.      else {
  49.          emit findNext(text, cs);
  50.      }
  51.  }
  52.   void FindDialog::enableFindButton(const QString &text)
  53.  {
  54.      findButton->setEnabled(!text.isEmpty());
  55.  }

main.cpp

  1. #include <QtGui/QApplication> #include "finddialog.h"
  2.   int main(int argc, char *argv[])
  3.  {
  4.      QApplication app(argc, argv);
  5.      FindDialog *dialog = new FindDialog;
  6.      dialog.show();
  7.       return app.exec();
  8.  }

6 replies

July 11, 2010

anselmolsm anselmolsm
Ant Farmer
417 posts

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
    1. Qt::CaseSensitivity
    instead of
    1. QtCaseSensitivity

in file finddialog.h:

in file main.cpp:

  • line 06:
    1. dialog->show()
 Signature 

Anselmo L. S. Melo (anselmolsm)
www.anselmolsm.org

July 11, 2010

doforumda doforumda
Lab Rat
161 posts

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

once again thanks

July 11, 2010

Tobias Hunger Tobias Hunger
Mad Scientist
3224 posts

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

July 11, 2010

doforumda doforumda
Lab Rat
161 posts

thanks for this information

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

July 11, 2010

Tobias Hunger Tobias Hunger
Mad Scientist
3224 posts

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.

July 13, 2010

Bobs Bobs
Lab Rat
33 posts

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.

 Signature 

Nokia Certified Qt Specialist.

 
  ‹‹ How can I style a QToolBar extension button icon via CSS      Qt-Designer, which approach to ui-files do you use? ››

You must log in to post a reply. Not a member yet? Register here!