QObject::connect simply "rejects" my object at compile-time(!)
-
C is a QObject derived class, I can use it successfully.
I get a compilation error on the "connect". If i'd change "this->controller", to "this", on the target, it will work fine. Something about the this->controller as the recipient causes this not to compile. I realize it must be something stupid, but the cause evades me.
@MyClass::MyClass(C * controller)
: QThread(NULL)
{
this->controller = controller;
QObject::connect(this, SIGNAL(OnResponse(ResponseClass*)), this->controller, SLOT(OnResponse(ResponseClass*))); // <---- "Compiler error: " error: no matching function for call to...."
}@ -
Hard to debug without the actual compiler error - you left out the real interesting part.
Some guesses:
- class C lacks the Q_OBJECT macro
- this->controller is not a pointer
-
Checked again. Q_OBJECT exists in C. this->controller is a pointer. One thing I did notice though. The class of the C had only a forward declaration as I couldn't use its *.h file due to circular reference. Could this be at play here?
-
Yes, this is the reason. The connect method takes a QObject pointer as the third argument. As long as the header file of class C is not included, the compiler does not know about the fact that you inherited from QObject and thus treads the pointer like a void pointer (at least kind-of in the sense of the error message, the compiler gurus may add some additional insight).
Be aware, that without including C's header file in MyClass implementation, you would never be able to call methods on the this->controller pointer.