July 14, 2010

doforumda doforumda
Lab Rat
161 posts

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

  1. undefined reference to 'vtable for FindDialog              finddialog.cpp 6

here is my code for finddialog.cpp

  1. #include <QtGui>
  2.  
  3. #include "finddialog.h"
  4.  
  5. FindDialog::FindDialog(QWidget *parent) :
  6.         QDialog(parent)
  7. {
  8.     QLabel *findLabel = new QLabel(tr("Enter the name of a contact:"));
  9.     lineEdit = new QLineEdit;
  10.  
  11.     findButton = new QPushButton(tr("&Find"));
  12.     findText = "";
  13.  
  14.     QHBoxLayout *layout = new QHBoxLayout;
  15.     layout->addWidget(findLabel);
  16.     layout->addWidget(lineEdit);
  17.     layout->addWidget(findButton);
  18.     setLayout(layout);
  19.     setWindowTitle(tr("Find Contact"));
  20.  
  21.     connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
  22.     connect(findButton, SIGNAL(clicked()), this, SLOT(accept()));
  23. }
  24.  
  25. void FindDialog::findClicked()
  26. {
  27.     QString text = lineEdit->text();
  28.  
  29.     if(text.isEmpty()) {
  30.         QMessageBox::information(this, tr("Empty Field"),
  31.                                  tr("Please Enter a name."));
  32.         return;
  33.     }
  34.     findText = text;
  35.     lineEdit->clear();
  36.     hide();
  37. }
  38.  
  39. QString FindDialog::getFindText()
  40. {
  41.     return findText;
  42. }

and here is finddialog.h

  1. #ifndef FINDDIALOG_H
  2.  
  3. #define FINDDIALOG_H
  4.  
  5. #include <QDialog>
  6.  
  7. class QLineEdit;
  8. class QPushButton;
  9.  
  10. class FindDialog : public QDialog
  11. {
  12.     Q_OBJECT
  13. public:
  14.     FindDialog(QWidget *parent = 0);
  15.     QString getFindText();
  16.  
  17. public slots:
  18.     void findClicked();
  19.  
  20. private:
  21.     QPushButton *findButton;
  22.     QLineEdit *lineEdit;
  23.     QString findText;
  24. };
  25.  
  26. #endif // FINDDIALOG_H

7 replies

July 14, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1607 posts

Try to clean and rebuild it. At first view code looks ok

July 14, 2010

doforumda doforumda
Lab Rat
161 posts

still same error

from Build Menu i select “clean all” and then Run it but same error

July 14, 2010

Juergen Bocklage-Ryannel Juergen Bocklage-Ryannel
Lab Rat
15 posts

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.

July 14, 2010

doforumda doforumda
Lab Rat
161 posts

thanks it works

March 3, 2013

bc913 bc913
Lab Rat
16 posts

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

  1. //finddialog.cpp
  2. #include <QtGui>
  3. #include "FindDialog.h"
  4.  
  5. FindDialog::FindDialog(QWidget *parent)
  6.         : QDialog(parent){
  7.     label = new QLabel(tr("Find &what: "));
  8.     lineEdit = new QLineEdit;
  9.     label->setBuddy(lineEdit);
  10.  
  11.     caseCheckBox = new QCheckBox(tr("Match &case"));
  12.     backwardCheckBox = new QCheckBox(tr("Search &Backward"));
  13.  
  14.     findButton = new QPushButton(tr("&Find"));
  15.     findButton->setDefault(true);
  16.     findButton->setEnabled(false);
  17.  
  18.     closeButton = new QPushButton(tr("Close"));
  19.  
  20.     connect(lineEdit, SIGNAL(textChanged(QString &)),this, SLOT(enableFindButton(QString &)));
  21.     connect(findButton, SIGNAL(clicked()), this, SLOT(findclicked()));
  22.     connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
  23.  
  24.     QHBoxLayout *topLeftLayout = new QHBoxLayout;
  25.     topLeftLayout->addWidget(label);
  26.     topLeftLayout->addWidget(lineEdit);
  27.  
  28.     QVBoxLayout *leftLayout = new QVBoxLayout;
  29.     leftLayout->addLayout(topLeftLayout);
  30.     leftLayout->addWidget(caseCheckBox);
  31.     leftLayout->addWidget(backwardCheckBox);
  32.  
  33.     QVBoxLayout *rightLayout = new QVBoxLayout;
  34.     rightLayout->addWidget(findButton);
  35.     rightLayout->addWidget(closeButton);
  36.     rightLayout->addStretch();
  37.  
  38.     QHBoxLayout *mainLayout = new QHBoxLayout;
  39.     mainLayout->addLayout(leftLayout);
  40.     mainLayout->addLayout(rightLayout);
  41.     setLayout(mainLayout);
  42.  
  43.     setWindowTitle(tr("Find"));
  44.     setFixedHeight(sizeHint().height());
  45.  
  46. }
  47.  
  48. void FindDialog::findClicked() // kullanici find butonunu tıkladığında calisir
  49. {
  50.     QString text = lineEdit->text();
  51.  
  52.     Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
  53.  
  54.     if (backwardCheckBox->isChecked()) { //backward Checkbox secili ise findPrevious sinyali yayar
  55.         emit findPrevious(text, cs);}
  56.     else {
  57.         emit findNext(text, cs);}
  58. }
  59.  
  60.  void FindDialog::enableFindButton(const QString &text) // satır editöründe metin degisiligi olunca finbutton calistirilir...
  61. {
  62.   findButton->setEnabled(!text.isEmpty());
  63. }

  1. //finddialog.h
  2. #ifndef FINDDIALOG_H
  3. #define FINDDIALOG_H
  4.  
  5. #include <QDialog>
  6.  
  7. class QCheckbox;
  8. class QLabel;
  9. class QLineEdit;
  10. class QPushButton;
  11.  
  12. class FindDialog : public QDialog
  13. {
  14.     Q_OBJECT
  15.  
  16. public:
  17.     FindDialog (QWidget *parent = 0);
  18. signals: // sinyal bildirimleri
  19.     void findNext(const QString &str, Qt::CaseSensitivity cs);
  20.     void findPrevious(const QString &str, Qt::CaseSensitivity cs);
  21. private slots: // yuva bildirimleri
  22.     void findclicked();
  23.     void enableFindButton(const QString &text);
  24. private:
  25.     QLabel *label;
  26.     QLineEdit *lineEdit;
  27.     QCheckbox *caseCheckBox;
  28.     QCheckbox *backwardCheckBox;
  29.     QPushButton *findButton;
  30.     QPushButton *closeButton;
  31. }
  32.  
  33. #endif // FINDDIALOG_H

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

March 5, 2013

iamfrankenstein iamfrankenst..
Lab Rat
5 posts

Aren’t you suppose to terminate a class definition with ‘;’?
I don’t see that in you header file finddialog.h

That 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.

March 6, 2013

Rondog Rondog
Lab Rat
27 posts

I think you need to declare and define a destructor

  1.     FindDialog (QWidget *parent = 0);
  2.     ~FindDialog(void);

If you are using virtual protected functions you should also make the destructor virtual as well.

 
  ‹‹ combobox in a qtableview      QFileDialog ››

You must log in to post a reply. Not a member yet? Register here!