PDA

View Full Version : [Help]Error in a Finder app.



"BumbleBee"
30th January 2011, 11:16
I am following atutorial from c++ gui with qt4 and i am making a "finder" dialog.

The code is:

finddialog.h.

1 #ifndef FINDDIALOG_H
2 #define FINDDIALOG_H
3 #include <QDialog>

4 class QCheckBox;
5 class QLabel;
6 class QLineEdit;
7 class QPushButton;

8 class FindDialog : public QDialog
9 {
10 Q_OBJECT
11 public:
12 FindDialog(QWidget *parent = 0);

13 signals:
14 void findNext(const QString &str, Qt::CaseSensitivity cs);
15 void findPrevious(const QString &str, Qt::CaseSensitivity cs);

16 private slots:
17 void findClicked();
18 void enableFindButton(const QString &text);
19 private:
20 QLabel *label;
21 QLineEdit *lineEdit;
22 QCheckBox *caseCheckBox;
23 QCheckBox *backwardCheckBox;
24 QPushButton *findButton;
25 QPushButton *closeButton;
26 };
27 #endif




finddialog.cpp

1 #include <QtGui>
2 #include "finddialog.h"

3 FindDialog::FindDialog(QWidget *parent)
4 : QDialog(parent)
5 {
6 label = new QLabel(tr("Find &what:"));
7 lineEdit = new QLineEdit;
8 label->setBuddy(lineEdit);

9 caseCheckBox = new QCheckBox(tr("Match &case"));
10 backwardCheckBox = new QCheckBox(tr("Search &backward"));
11 findButton = new QPushButton(tr("&Find"));
12 findButton->setDefault(true);
13 findButton->setEnabled(false);
14 closeButton = new QPushButton(tr("Close"));

15 connect(lineEdit, SIGNAL(textChanged(const QString &)),
16 this, SLOT(enableFindButton(const QString &)));
17 connect(findButton, SIGNAL(clicked()),
18 this, SLOT(findClicked()));
19 connect(closeButton, SIGNAL(clicked()),
20 this, SLOT(close()));

21 QHBoxLayout *topLeftLayout = new QHBoxLayout;
22 topLeftLayout->addWidget(label);
23 topLeftLayout->addWidget(lineEdit);
24 QVBoxLayout *leftLayout = new QVBoxLayout;
25 leftLayout->addLayout(topLeftLayout);
26 leftLayout->addWidget(caseCheckBox);
27 leftLayout->addWidget(backwardCheckBox);
28 QVBoxLayout *rightLayout = new QVBoxLayout;

29 rightLayout->addWidget(findButton);
30 rightLayout->addWidget(closeButton);
31 rightLayout->addStretch();
32 QHBoxLayout *mainLayout = new QHBoxLayout;
33 mainLayout->addLayout(leftLayout);
34 mainLayout->addLayout(rightLayout);
35 setLayout(mainLayout);

36 setWindowTitle(tr("Find"));
37 setFixedHeight(sizeHint().height());
38 }

39 void FindDialog::findClicked()
40 {
41 QString text = lineEdit->text();
42 Qt::CaseSensitivity cs =
43 caseCheckBox->isChecked() ? Qt::CaseSensitive
44 : Qt::CaseInsensitive;
45 if (backwardCheckBox->isChecked()) {
46 emit findPrevious(text, cs);
47 } else {
48 emit findNext(text, cs);
49 }
50 }
51 void FindDialog::enableFindButton(const QString &text)
52 {
53 findButton->setEnabled(!text.isEmpty());
54 }



main.cpp

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


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.

stampede
30th January 2011, 11:57
I've just compiled your code, no errors. Make sure you do a clean build ( make clean, qmake, make )

tbscope
30th January 2011, 11:57
The code you posted compiles and runs without a problem.

"BumbleBee"
30th January 2011, 12:47
Can I guys please have your MSN?
I need help..lol
Thanks.

Zlatomir
30th January 2011, 12:53
Try what stampede already suggested,

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

"BumbleBee"
30th January 2011, 13:06
I cleared,rebuilt..still same.
Started a new project with with same code..still gives same errors....

Lykurg
30th January 2011, 13:15
please post the full compiler output.

"BumbleBee"
30th January 2011, 13:17
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

stampede
30th January 2011, 13:21
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.

"BumbleBee"
30th January 2011, 13:26
OMG it is so complicated...
I don't know how to qmake lol
I just press the Run button and it gives me error....

Lykurg
30th January 2011, 13:31
Have a look at the menu bar "Build". There you find all actions you need.

Zlatomir
30th January 2011, 13:32
From Build menu menu in Creator you use: Clean All then run qmake then Rebuild

It looks something like this:
5839

"BumbleBee"
30th January 2011, 13:35
I did so..step by step..still same!
Can anyone give me MSN?

stampede
30th January 2011, 13:36
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.

"BumbleBee"
30th January 2011, 13:45
Haha..no..where is this console?

wysota
30th January 2011, 15:07
Right next to the "format c:" button...

Zlatomir
30th January 2011, 15:28
Also check that you didn't by mistake deleted the public: from the header file in your actual project:

class FindDialog : public QDialog
{
Q_OBJECT
public: //this one
FindDialog(QWidget *parent = 0);
//...