Not only QWidget sibclasses but all classes that use/implement signals and slots have to have the Q_OBJECT macro in order to be processed by moc. So, it is mandatory in your case.It was suggested that I may need a Q_OBJECT in the Thread class; I didn’t think so because I’m not using a widget (may be an incorrect assumption on my part). I put it in the code and got linker errors:
Do you implement two classes in the same cpp? There was a similar problem on the forum, still unsolved unfortunately. Try splitting the declarations and implementations for classes containing the Q_OBJECT macro."Undefined reference to vtable for CHostIFReceive."
My understanding is that it thinks I’m using a virtual object that hasn’t been declared, I didn’t think I was.
You'll have to post the thread code for this. Probably something got mixed up.2) Another suggesting was that I should not create the QUpdSocket in the QThread constructor but in the run() method (all the examples I’ve seen have it in the constructor). I got the following runtime errors:
"QObject can not create children for a parent that is in a different thread.
(Parent is QThread(0xbfefb140), parent’s thread is QThread(0x9e9c2e8), current thread is QThread(0xbfefb140)
Object::connect: No such slot QThread:rocessPendingDatagrams."
It might be that the worker thread object lives in the GUI thread. If you move it to itself after it is started could solve the problem.
If the socket lives in the worker thread there will be no need to specify the connection type. It will default to direct.Final suggestion was to make sure that I pass in Qt:irectConnection as the fifth parameter for the connect() method. That had no affect.
Also, make sure you start the event loop in the thread with exec, otherwise thread slots won't work.
Bookmarks