Author Topic: What is the problem with QT?  (Read 11492 times)

Offline Haziq

  • Single posting newcomer
  • *
  • Posts: 5
What is the problem with QT?
« on: October 13, 2009, 08:49:22 pm »
I have started to learn building applications using QT GUI library. I was trying an example from a book where I have derived a class 'FindDialog' from 'QDialog'. Class is defined in a separate header file 'finddialog.h'. I get some strange errors like "undefined reference to vtable for FindDialog". Below, I have copied all the errors. Can anyone help me out, please?







obj\Release\finddialog.o:finddialog.cpp:(.text+0x24)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x81)||undefined reference to `vtable for FindDialog'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x88)||undefined reference to `vtable for FindDialog'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x18f)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x229)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x2d2)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x39d)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x78c)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0xa51)||undefined reference to `vtable for FindDialog'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0xa58)||undefined reference to `vtable for FindDialog'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0xb5f)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0xbf9)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0xc95)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0xd68)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x1167)||undefined reference to `FindDialog::staticMetaObject'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x1456)||undefined reference to `FindDialog::findNext(QString const&, Qt::CaseSensitivity)'|
obj\Release\finddialog.o:finddialog.cpp:(.text+0x14d5)||undefined reference to `FindDialog::findPrevious(QString const&, Qt::CaseSensitivity)'|
||=== Build finished: 17 errors, 0 warnings ===|

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: What is the problem with QT?
« Reply #1 on: October 13, 2009, 09:05:06 pm »
Do you have finddialog.cpp added to the project?
Have you linked you project to the correct qt library?

p.s. please see there: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F and if you don't find the problem post the full output here.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Haziq

  • Single posting newcomer
  • *
  • Posts: 5
Re: What is the problem with QT?
« Reply #2 on: October 14, 2009, 06:29:51 am »
Sorry, I could not solve my problem.

Yes, finddialog.cpp is added.

Project is linked to QTGui4 and QTCore4 libraries.

Given below are the files and the build log in the end.
-----------------------------------------------------------------------------------------------------
finddialog.h:
#ifndef FINDDIALOG_H_INCLUDED
#define FINDDIALOG_H_INCLUDED

#include <QDialog>

class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;

class FindDialog : public QDialog
{
    Q_OBJECT

    public:
        FindDialog(QWidget *parent = 0);

    signals:
        void findNext(const QString &str, Qt::CaseSensitivity cs);
        void findPrevious(const QString &str, Qt::CaseSensitivity cs);

    private slots:
        void findClicked();
        void enableFindButton(const QString &text);

    private:
        QLabel *label;
        QLineEdit *lineEdit;
        QCheckBox *caseCheckBox;
        QCheckBox *backwardCheckBox;
        QPushButton *findButton;
        QPushButton *closeButton;
};

#endif // FINDDIALOG_H_INCLUDED
-----------------------------------------------------------------------------------------------------

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(const QString &)),
    this, SLOT(enableFindButton(const 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()
{
    QString text = lineEdit->text();
    Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
    if (backwardCheckBox->isChecked()) {
    emit findPrevious(text, cs);
    } else {
    emit findNext(text, cs);
    }
}

void FindDialog::enableFindButton(const QString &text)
{
    findButton->setEnabled(!text.isEmpty());
}
-----------------------------------------------------------------------------------------------------

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

Build Log:

-------------- Build: Release in DialogQT ---------------

mingw32-g++.exe -LC:\Qt\2009.04\qt\lib  -o bin\Release\DialogQT.exe obj\Release\main.o obj\Release\finddialog.o   -s  -lQtCore4 -lQtGui4  -mwindows
obj\Release\finddialog.o:finddialog.cpp:(.text+0x24): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x81): undefined reference to `vtable for FindDialog'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x88): undefined reference to `vtable for FindDialog'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x18f): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x229): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x2d2): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x39d): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x78c): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x9f4): more undefined references to `FindDialog::staticMetaObject' follow
obj\Release\finddialog.o:finddialog.cpp:(.text+0xa51): undefined reference to `vtable for FindDialog'
obj\Release\finddialog.o:finddialog.cpp:(.text+0xa58): undefined reference to `vtable for FindDialog'
obj\Release\finddialog.o:finddialog.cpp:(.text+0xb5f): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0xbf9): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0xc95): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0xd68): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x1167): undefined reference to `FindDialog::staticMetaObject'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x1456): undefined reference to `FindDialog::findNext(QString const&, Qt::CaseSensitivity)'
obj\Release\finddialog.o:finddialog.cpp:(.text+0x14d5): undefined reference to `FindDialog::findPrevious(QString const&, Qt::CaseSensitivity)'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
17 errors, 0 warnings
 

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: What is the problem with QT?
« Reply #3 on: October 14, 2009, 09:28:53 am »
Try adding implementation for these two:

        void findNext(const QString &str, Qt::CaseSensitivity cs);
        void findPrevious(const QString &str, Qt::CaseSensitivity cs);
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Haziq

  • Single posting newcomer
  • *
  • Posts: 5
Re: What is the problem with QT?
« Reply #4 on: October 14, 2009, 07:00:28 pm »
I have tried implementing these two, but it only removes the last two errors. The other 15 errors are still there.
Infact, I even tried a very basic application where I derived a class from QDialog. But, even there it shows these "undefined reference to vtable" errors.

It may be worth noting that if I don't derive a class of my own, then QT works.

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 203
Re: What is the problem with QT?
« Reply #5 on: October 14, 2009, 07:25:46 pm »
Try implementing the missing virtual methods (~FindDialog).

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: What is the problem with QT?
« Reply #6 on: October 14, 2009, 07:46:18 pm »
Code
obj\Release\finddialog.o:finddialog.cpp:(.text+0x1167): undefined reference to `FindDialog::staticMetaObject'

This is QT stuff, probably you have not added all the QT macro that are required to derive a class.
Please read the documentation about deriving QT classes.
And use google :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: What is the problem with QT?
« Reply #7 on: October 15, 2009, 02:58:21 pm »
This is QT stuff,

and not really related to C::B.

I lock the topic now, because it violates our forum rules.