Results 1 to 17 of 17

Thread: [Help]Error in a Finder app.

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 11:22.

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, 11:05
  2. Replies: 3
    Last Post: 23rd January 2011, 12: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, 11:24
  4. Replies: 1
    Last Post: 25th October 2008, 19:18
  5. qTextEdit error - clipboard error
    By bruccutler in forum Qt Programming
    Replies: 1
    Last Post: 21st May 2007, 09: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.