QObject question please, it’s simple but I can’t get it!!
Hi all
I have a question about writing QObject in the main.cpp file, it’s seems like a trivial task, but I can’t believe it, I can’t get it to work, and I don’t know what I miss in this trivial program.
- {
- Q_OBJECT
- public:
- public slots:
- void closed();
- };
- void TempClass::closed()
- {
- }
- {
- }
I’ve tried to put it before the main method but it’s not working, so I’ve putted after the main method with class forward declaration but also it’s not working.
with vtable reference error.
I’ve also tried to put all methods inside the class including the signal but having no luck at all.
do I miss something in QObject implementation? although I’ve read the QObject details many times.
Or it’s a problem with QT Creator.
You can replicate this problem easily.
Thanks in Advance
5 replies
error: main.moc: No such file or directory
Did you run qmake again?
sorry for that but the solution doesn’t work with the above message.
It works.
- main.cpp project.pro
main.cpp
- {
- Q_OBJECT
- public:
- public slots:
- void closed() { }
- };
- #include "main.moc"
- int main(int argc, char *argv[])
- {
- TempClass temp;
- return app.exec();
- }
project.pro
- TEMPLATE = app
- TARGET =
- DEPENDPATH += .
- INCLUDEPATH += .
- # Input
- SOURCES += main.cpp
- g++ -Wl,-O1 -o project main.o -L/usr/lib -lQtGui -L/usr/lib -L/usr/X11R6/lib -lQtCore -lpthread
- main.cpp main.moc main.o Makefile project project.pro
project is the binary. Attention to the first line of the compilation output, there you can see moc being called to generate main.moc.
You must log in to post a reply. Not a member yet? Register here!




