User forums > Using Code::Blocks
What is the problem with QT?
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.
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);
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.
Navigation
[0] Message Index
[#] Next page
Go to full version