PDA

View Full Version : QMake issue



Caius Aérobus
19th October 2009, 16:12
I get an error at linking stage since I add a new class above my main() (undefined reference to `vtable for myHelp'). I have read that such an error may be due to the lack of a moc_ file and surprisingly Qmake does not generate a moc_ file for this file named main.cxx
Any help?


class myHelp : public QMessageBox
{
Q_OBJECT

public:
myHelp(QString text=QString());
virtual ~myHelp() {};

public slots:
int minimumWidth() const {return 800;};
QSize minimumSize() const {return QSize(800, 800);};
};

myHelp::myHelp(QString text)
: QMessageBox(QMessageBox::NoIcon, QString::fromLocal8Bit("My message"), text, QMessageBox::Ok)
{};

int main()
...

wysota
19th October 2009, 22:02
QMake only scans header files for Q_OBJECT macro. Either add an '#include "main.moc"' statement to your file (which explicitely tells qmake to invoke moc on the file) or move the class header containing the Q_OBJECT macro to a header file.

Caius Aérobus
20th October 2009, 13:01
QMake only scans header files for Q_OBJECT macro. Either add an '#include "main.moc"' statement to your file (which explicitely tells qmake to invoke moc on the file) or move the class header containing the Q_OBJECT macro to a header file.

Hmmm, I do not understand. I declare the class with the Q_OBJECT macro in a file named "main.cxx" so which statement should I include and in which file please?

wysota
20th October 2009, 13:03
#include "main.moc" after the class definition in main.cxx

Caius Aérobus
20th October 2009, 13:10
#include "main.moc" after the class definition in main.cxx

I get:

main.cxx:33:19: error: main.moc: No such file or directory

May be is it necessary to add some quotes to prevent the C++ preprocessor to process this line?

wysota
20th October 2009, 15:44
No, you need to run qmake after adding the statement.