Need help in Qt code
-
hi
I am working on a Qt examples on this link "Your text to link here...":http://doc.trolltech.com/4.6/tutorials-addressbook-part5.html
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"
FindDialog::FindDialog(QWidget *parent) :
QDialog(parent)
{
QLabel *findLabel = new QLabel(tr("Enter the name of a contact:"));
lineEdit = new QLineEdit;findButton = new QPushButton(tr("&Find")); findText = ""; QHBoxLayout *layout = new QHBoxLayout; 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()
{
QString text = lineEdit->text();if(text.isEmpty()) { QMessageBox::information(this, tr("Empty Field"), tr("Please Enter a name.")); return; } findText = text; lineEdit->clear(); hide();
}
QString FindDialog::getFindText()
{
return findText;
}
@and here is finddialog.h
@#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include <QDialog>
class QLineEdit;
class QPushButton;class FindDialog : public QDialog
{
Q_OBJECT
public:
FindDialog(QWidget *parent = 0);
QString getFindText();public slots:
void findClicked();private:
QPushButton *findButton;
QLineEdit *lineEdit;
QString findText;
};#endif // FINDDIALOG_H
@ -
Try to clean and rebuild it. At first view code looks ok
-
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,
- error: C2628: 'FindDialog' followed by 'int' is illegal (did you forget a ';'?)
- error: C3874: return type of 'main' should be 'int' instead of 'FindDialog'
- 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_OBJECTpublic:
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();
}
@ -
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.