Results 1 to 17 of 17

Thread: [Help]Error in a Finder app.

  1. #1
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default [Help]Error in a Finder app.

    I am following atutorial from c++ gui with qt4 and i am making a "finder" dialog.

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

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

    Qt Code:
    1. main.cpp
    2.  
    3. 1 #include <QApplication>
    4. 2 #include "finddialog.h"
    5. 3 int main(int argc, char *argv[])
    6. 4 {
    7. 5 QApplication app(argc, argv);
    8. 6 FindDialog *dialog = new FindDialog;
    9. 7 dialog->show();
    10. 8 return app.exec();
    11. 9 }
    To copy to clipboard, switch view to plain text mode 

    This is books code^^
    But in Qt it gives me an error(finddialog.cpp)
    line 49(forum's lines...:/) and says expected token ';',got {
    same in line 60.
    So what I do,is to put a ';' on line 48 and 59..then ok
    However when building i get the errors:
    FindDialog::FindDialog(QWidget*) is private line 12(Qt lines),file finddialog.h
    and withtin this context main.cpp line 6(qt lines..)

    Help please.
    Last edited by "BumbleBee"; 30th January 2011 at 12:22.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [Help]Error in a Finder app.

    I've just compiled your code, no errors. Make sure you do a clean build ( make clean, qmake, make )

  3. #3
    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: [Help]Error in a Finder app.

    The code you posted compiles and runs without a problem.

  4. #4
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: [Help]Error in a Finder app.

    Can I guys please have your MSN?
    I need help..lol
    Thanks.

  5. #5
    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: [Help]Error in a Finder app.

    Try what stampede already suggested,

    Or (from Build menu if you use Creator): Clean All, run qmake, Rebuild

  6. #6
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: [Help]Error in a Finder app.

    I cleared,rebuilt..still same.
    Started a new project with with same code..still gives same errors....

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: [Help]Error in a Finder app.

    please post the full compiler output.

  8. #8
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: [Help]Error in a Finder app.

    D:/Qt/projects/finder-build-desktop/../finder/finddialog.h:: In function 'int qMain(int, char**)': finddialog.h
    D:/Qt/projects/finder-build-desktop/../finder/finddialog.h:18: error: 'FindDialog::FindDialog(QWidget*)' is private finddialog.h
    D:/Qt/projects/finder-build-desktop/../finder/main.cpp:11: error: within this context main.cpp

  9. #9
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [Help]Error in a Finder app.

    I cleared,rebuilt..still same.
    Started a new project with with same code..still gives same errors....
    Here is what I did:
    - placed your sources into separate folder
    - 'cd' into that directory
    - qmake -project
    - qmake
    - make

    Compiled without errors. Try it this way, maybe you have something messed up in your QtCreator settings.

  10. #10
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: [Help]Error in a Finder app.

    OMG it is so complicated...
    I don't know how to qmake lol
    I just press the Run button and it gives me error....

  11. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: [Help]Error in a Finder app.

    Have a look at the menu bar "Build". There you find all actions you need.

  12. #12
    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: [Help]Error in a Finder app.

    From Build menu menu in Creator you use: Clean All then run qmake then Rebuild

    It looks something like this:
    build_menu.jpg

  13. #13
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: [Help]Error in a Finder app.

    I did so..step by step..still same!
    Can anyone give me MSN?

  14. #14
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [Help]Error in a Finder app.

    OMG it is so complicated...
    I don't know how to qmake lol
    Maybe I should have specified that - I was using a console. Do you know how to use it ? I've just posted the commands I've entered in system console window.

  15. #15
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: [Help]Error in a Finder app.

    Haha..no..where is this console?

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [Help]Error in a Finder app.

    Right next to the "format c:" button...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    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: [Help]Error in a Finder app.

    Also check that you didn't by mistake deleted the public: from the header file in your actual project:
    Qt Code:
    1. class FindDialog : public QDialog
    2. {
    3. Q_OBJECT
    4. public: //this one
    5. FindDialog(QWidget *parent = 0);
    6. //...
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. no compile error, but error on run with QMenu QAction
    By sincnarf in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2011, 12:05
  2. Replies: 3
    Last Post: 23rd January 2011, 13:15
  3. fatal error C1001: An internal error has occurred in the compiler
    By noodles in forum Installation and Deployment
    Replies: 0
    Last Post: 12th August 2010, 12:24
  4. Replies: 1
    Last Post: 25th October 2008, 20:18
  5. qTextEdit error - clipboard error
    By bruccutler in forum Qt Programming
    Replies: 1
    Last Post: 21st May 2007, 10:21

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.