need help in Qt code
hi
I am working on a Qt examples on this link Your text to link here… [doc.trolltech.com]
i write the complete code but it gives me this error
- undefined reference to 'vtable for FindDialog finddialog.cpp 6
here is my code for finddialog.cpp
- #include <QtGui>
- #include "finddialog.h"
- {
- lineEdit = new QLineEdit;
- findText = "";
- layout->addWidget(findLabel);
- layout->addWidget(lineEdit);
- layout->addWidget(findButton);
- setLayout(layout);
- setWindowTitle(tr("Find Contact"));
- connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
- connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
- }
- void FindDialog::findClicked()
- {
- if(text.isEmpty()) {
- tr("Please Enter a name."));
- return;
- }
- findText = text;
- lineEdit->clear();
- hide();
- }
- {
- return findText;
- }
and here is finddialog.h
- #ifndef FINDDIALOG_H
- #define FINDDIALOG_H
- #include <QDialog>
- class QLineEdit;
- class QPushButton;
- {
- Q_OBJECT
- public:
- public slots:
- void findClicked();
- private:
- QString findText;
- };
- #endif // FINDDIALOG_H
7 replies
Seems you need to run qmake again. If you use QtCreator, right click on project and select “Run qmake”.
The missing vtable comes from the issue you have the Q_OBJECT macro included, but qmake has not flagged the class for meta-object compilation (moc). Running qmake will add the class to the list of “I need moc” items.
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,
1. error: C2628: ‘FindDialog’ followed by ‘int’ is illegal (did you forget a ‘;’?)
2. 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 *’
4. Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
- //finddialog.cpp
- #include <QtGui>
- #include "FindDialog.h"
- lineEdit = new QLineEdit;
- label->setBuddy(lineEdit);
- findButton->setDefault(true);
- findButton->setEnabled(false);
- connect(findButton, SIGNAL(clicked()), this, SLOT(findclicked()));
- connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
- topLeftLayout->addWidget(label);
- topLeftLayout->addWidget(lineEdit);
- leftLayout->addLayout(topLeftLayout);
- leftLayout->addWidget(caseCheckBox);
- leftLayout->addWidget(backwardCheckBox);
- rightLayout->addWidget(findButton);
- rightLayout->addWidget(closeButton);
- rightLayout->addStretch();
- mainLayout->addLayout(leftLayout);
- mainLayout->addLayout(rightLayout);
- setLayout(mainLayout);
- setWindowTitle(tr("Find"));
- setFixedHeight(sizeHint().height());
- }
- void FindDialog::findClicked() // kullanici find butonunu tıkladığında calisir
- {
- 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;
- {
- Q_OBJECT
- public:
- signals: // sinyal bildirimleri
- private slots: // yuva bildirimleri
- void findclicked();
- private:
- }
- #endif // FINDDIALOG_H
- //main.cpp
- #include <QApplication>
- #include "FindDialog.h"
- int main(int argc, char *argv[])
- {
- FindDialog *dialog = new FindDialog;
- dialog->show();
- return app.exec();
- }
You must log in to post a reply. Not a member yet? Register here!




