Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Need help in Qt code
QtWS25 Last Chance

Need help in Qt code

Scheduled Pinned Locked Moved General and Desktop
8 Posts 6 Posters 5.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    doforumda
    wrote on last edited by
    #1

    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("&amp;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
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        doforumda
        wrote on last edited by
        #3

        still same error

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

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jryannel
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            doforumda
            wrote on last edited by
            #5

            thanks it works

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bc913
              wrote on last edited by
              #6

              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"

              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();
              

              }
              @

              1 Reply Last reply
              0
              • I Offline
                I Offline
                iamfrankenstein
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Rondog
                  wrote on last edited by
                  #8

                  I think you need to declare and define a destructor

                  @
                  FindDialog (QWidget *parent = 0);
                  ~FindDialog(void);
                  @

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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved