Results 1 to 4 of 4

Thread: need help in Qt example

  1. #1
    Join Date
    Jul 2010
    Posts
    18
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default 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

    Qt Code:
    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'
    To copy to clipboard, switch view to plain text mode 

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

    finddialog.cpp
    Qt Code:
    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. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    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. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: need help in Qt example

    You didn't copy the actual error message

    And here is a little mistake:
    Qt Code:
    1. FindDialog *dialog = new FindDialog;
    2. dialog->show(); //Here you need the -> operator because dialog is a pointer
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2010
    Posts
    18
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default Re: need help in Qt example

    i copy everything in Compile output tab
    on Build issues tab i find this error

    ":: error: [debug/main.o] Error 1"

    if this is still not the exact error then please tell where can i find the exact error. I am newbie.

    i change dialog.show(); to dialog->show(); but still the same error

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: need help in Qt example

    More errors:

    Qt Code:
    1. class QlineEdit;
    To copy to clipboard, switch view to plain text mode 

    Should be
    Qt Code:
    1. class QLineEdit;
    To copy to clipboard, switch view to plain text mode 

    Not an error but it annoys me:

    Qt Code:
    1. #include "finddialog.h";
    To copy to clipboard, switch view to plain text mode 

    Should be:
    Qt Code:
    1. #include "finddialog.h"
    To copy to clipboard, switch view to plain text mode 

    And the last error:

    Qt Code:
    1. QtCaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
    To copy to clipboard, switch view to plain text mode 

    should be:

    Qt Code:
    1. Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
    To copy to clipboard, switch view to plain text mode 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.