Question about an example of “C++ GUI Programming with Qt 4
-
Hi,
I am working on the same example with QT 4.8.4 and QT Creator 2.6.2. When I run it, several errors including the followings occur. I have tried all the ways from the forum but I haven’t fixed.
I have cleaned the project, rebuild and run qmake. But, it doesn’t solve. Any help is appreciated.
Regards,
- error: C2628: ‘FindDialog’ followed by ‘int’ is illegal (did you forget a ‘;’?)
- error: C3874: return type of ‘main’ should be ‘int’ instead of ‘FindDialog’ 3. error: C2664: ‘FindDialog::FindDialog(QWidget *)’ : cannot convert parameter 1 from ‘int’ to ‘QWidget *’
- Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
@ //finddialog.cpp
#include <QtGui>
#include "FindDialog.h"FindDialog::FindDialog(QWidget *parent) : QDialog(parent){ label = new QLabel(tr("Find &what: ")); lineEdit = new QLineEdit; label->setBuddy(lineEdit); caseCheckBox = new QCheckBox(tr("Match &case")); backwardCheckBox = new QCheckBox(tr("Search &Backward")); findButton = new QPushButton(tr("&Find")); findButton->setDefault(true); findButton->setEnabled(false); closeButton = new QPushButton(tr("Close")); connect(lineEdit, SIGNAL(textChanged(QString &)),this, SLOT(enableFindButton(QString &))); connect(findButton, SIGNAL(clicked()), this, SLOT(findclicked())); connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *topLeftLayout = new QHBoxLayout; topLeftLayout->addWidget(label); topLeftLayout->addWidget(lineEdit); QVBoxLayout *leftLayout = new QVBoxLayout; leftLayout->addLayout(topLeftLayout); leftLayout->addWidget(caseCheckBox); leftLayout->addWidget(backwardCheckBox); QVBoxLayout *rightLayout = new QVBoxLayout; rightLayout->addWidget(findButton); rightLayout->addWidget(closeButton); rightLayout->addStretch(); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addLayout(leftLayout); mainLayout->addLayout(rightLayout); setLayout(mainLayout); setWindowTitle(tr("Find")); setFixedHeight(sizeHint().height()); } void FindDialog::findClicked() // kullanici find butonunu tıkladığında calisir { QString text = lineEdit->text(); Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive; if (backwardCheckBox->isChecked()) { //backward Checkbox secili ise findPrevious sinyali yayar emit findPrevious(text, cs);} else { emit findNext(text, cs);} } void FindDialog::enableFindButton(const QString &text) // satır editöründe metin degisiligi olunca finbutton calistirilir... { findButton->setEnabled(!text.isEmpty()); } //finddialog.h #ifndef FINDDIALOG_H #define FINDDIALOG_H #include <QDialog> class QCheckbox; class QLabel; class QLineEdit; class QPushButton; class FindDialog : public QDialog { Q_OBJECT public: FindDialog (QWidget *parent = 0); signals: // sinyal bildirimleri void findNext(const QString &str, Qt::CaseSensitivity cs); void findPrevious(const QString &str, Qt::CaseSensitivity cs); private slots: // yuva bildirimleri void findclicked(); void enableFindButton(const QString &text); private: QLabel *label; QLineEdit *lineEdit; QCheckbox *caseCheckBox; QCheckbox *backwardCheckBox; QPushButton *findButton; QPushButton *closeButton; } #endif // FINDDIALOG_H //main.cpp #include <QApplication> #include "FindDialog.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); FindDialog *dialog = new FindDialog; dialog->show(); return app.exec(); }
@
-
Hi,
In the header file did you end the class definition with a semi-colon. The example you have shown hasn't.
-
Hi,
Yer, you are right. I forgot it but after I have added the semi-colon, error situation continues. Only the number of errors were decreased...
Only, the errors about QCheckBox still exist.
-
Can you provide the error(errors) and line(lines) in the code the compiler is pointing to?
-
Here is the error list,
@error C2440: '=' : cannot convert from 'QCheckBox *' to 'QCheckbox *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
..\bc1\finddialog.cpp(12) : error C2440: '=' : cannot convert from 'QCheckBox *' to 'QCheckbox *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
..\bc1\finddialog.cpp(30) : error C2664: 'QBoxLayout::addWidget' : cannot convert parameter 1 from 'QCheckbox *' to 'QWidget *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
..\bc1\finddialog.cpp(31) : error C2664: 'QBoxLayout::addWidget' : cannot convert parameter 1 from 'QCheckbox *' to 'QWidget *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
..\bc1\finddialog.cpp(48) : error C2039: 'findClicked' : is not a member of 'FindDialog'
d:\bc913\egitim\yazilim\qt\proje\bc1\FindDialog.h(11) : see declaration of 'FindDialog'
..\bc1\finddialog.cpp(50) : error C2065: 'lineEdit' : undeclared identifier
..\bc1\finddialog.cpp(50) : error C2227: left of '->text' must point to class/struct/union/generic type
type is ''unknown-type''
..\bc1\finddialog.cpp(52) : error C2065: 'caseCheckBox' : undeclared identifier
..\bc1\finddialog.cpp(52) : error C2227: left of '->isChecked' must point to class/struct/union/generic type
type is ''unknown-type''
..\bc1\finddialog.cpp(54) : error C2065: 'backwardCheckBox' : undeclared identifier
..\bc1\finddialog.cpp(54) : error C2227: left of '->isChecked' must point to class/struct/union/generic type
type is ''unknown-type''
..\bc1\finddialog.cpp(55) : error C3861: 'findPrevious': identifier not found
..\bc1\finddialog.cpp(57) : error C3861: 'findNext': identifier not found@ -
Error lines:
//finddialog.cppLines: 11,12,30,31,48,50,52,55, 56, 58
-
Okay so you have a typo for QCheckbox. it should be QCheckBox. please check your code and let us know of any other issue.
-
you also need to include the QString header. thats why it is complaining on line 50. The compiler has no idea about QString
-
Thanks a lot,
Also, I have mistaken on findclicked function. I will be much more careful,
Regards,
-
Aren’t you suppose to terminate a class definition with ‘;’?
I don’t see that in you header file finddialog.hThat is what the compiler means with “did you forget a ‘;’?”
I’ll check in a few hours to see your response if its not the case.(Why have you posted you question twice??)
-
Ow its closed now??