News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

What is the problem with QT?

Started by Haziq, October 13, 2009, 08:49:22 PM

Previous topic - Next topic

Haziq

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 ===|

oBFusCATed

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!]

Haziq

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

oBFusCATed

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!]

Haziq

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.

danselmi

Try implementing the missing virtual methods (~FindDialog).
spell checker plugin: [url="http://developer.berlios.de/projects/spellchecker/"]http://developer.berlios.de/projects/spellchecker/[/url]
nassi shneiderman plugin: [url="http://developer.berlios.de/projects/nassiplugin"]http://developer.berlios.de/projects/nassiplugin[/url]

oBFusCATed


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!]

Jenna

Quote from: oBFusCATed on October 14, 2009, 07:46:18 PM
This is QT stuff,

and not really related to C::B.

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