Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec edition)
I have searched for another similar threads about "undefined Reference: vtable" but still can't figured out how to solve this
my OS is windows xp sp3
my compiler is gcc4.5 mingw
my IDE is code::blokcs 10.05
my Qt version is 4.7.1
below is the code come from the book--C++ GUI Programming with Qt4, sec edition
Code:
#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include <QDialog>
{
Q_OBJECT
public:
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:
};
#endif
Code:
#include <QtGui>
#include "finddialog.h"
FindDialog
::FindDialog(QWidget *parent
){
label
= new QLabel(tr
("Find &what:"));
label->setBuddy(lineEdit);
caseCheckBox
= new QCheckBox(tr
("Match &case"));
backwardCheckBox
= new QCheckBox(tr
("Search &backward"));
findButton->setDefault(true);
findButton->setEnabled(false);
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()));
topLeftLayout->addWidget(label);
topLeftLayout->addWidget(lineEdit);
leftLayout->addLayout(topLeftLayout);
leftLayout->addWidget(caseCheckBox);
leftLayout->addWidget(backwardCheckBox);
rightLayout->addWidget(findButton);
rightLayout->addWidget(closeButton);
rightLayout->addStretch();
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
setWindowTitle(tr("Find"));
setFixedHeight(sizeHint().height());
}
void FindDialog::findClicked()
{
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());
}
when I press the F9 button, the compiler always give me error message like
Quote:
undefined reference to 'vtable for findDialog'
undefined reference to `FindDialog::staticMetaObject'
The example of chapter1 of this book could be compiled perfectly, but the example of
the chapter2 can't work at all.
Thanks a lot
Re: Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec editi
your IDE is not running qmake and/or not linking to the files generated by moc.
try to compile the example on command line via
qmake
make (or mingw-make )
Re: Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec editi
Thanks for your reply
I open the MinGW Command Prompt, and type the command
Quote:
qmake -project
qmake
make
below is the error messages
Quote:
mingw32-make[1]:***[debug\find.exe] Error 1
mingw32-make : *** [debug] Error 2
what mistakes do I make?Thanks
ps : I download my gcc from this site
htp://tdm-gcc.tdragon.net/
Added after 24 minutes:
I solved the probelm
Quote:
<QT4 directory>\bin\moc.exe myfile.h -o moc_myfile.cpp
Then include the file moc_myfile.cpp in the project as well.
How could I make the IDE do this automatically for me?
Thanks
Re: Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec editi
Maybe you should use Qt Creator (is an very good IDE, and it "looks" exactly the same on all platforms)
It comes together with Qt SDK for Windows.
Or use Visual Studio or Eclipse, Qt framework has add-ins that integrate the Qt tools into those.
Re: Undifined Refrence: vtable(the example of C++ GUI Programming with Qt4, sec editi
The header file containing Q_OBJECT macro has to be present in the HEADERS variable of a qmake project and qmake needs to be ran after adding the macro to the file.