PDA

View Full Version : SigSlot conn from base classs to subclass



stevey
5th September 2009, 04:05
Hi,

I'm subclassing QHttp to a class called HttpSyncr.

I have the following slot declarations in HttpSyncr.h:


public slots:
void ReceiveResponseHeader(const QHttpResponseHeader& header);
void HttpRequestStarted(int id);
void HttpRequestFinished(int id, bool error);


This is how I'm connecting:


HttpSyncr::HttpSyncr(QObject *parent)
: QHttp(parent)
{
bool res = connect(this, SIGNAL(responseHeaderReceived(const QHttpResponseHeader&)), this, SLOT(ReceiveResponseHeader(const QHttpResponseHeader&)));
res = connect(this, SIGNAL(requestStarted(int)), this, SLOT(HttpRequestStarted(int)));
res = connect(this, SIGNAL(requestFinished(int, bool)), this, SLOT(HttpRequestFinished(int, bool)));

}


I figured that simply specifying 'this' as both source and target would be okay, but the slot is getting defined incorrectly. My debug output from the connect() function is:


Object::connect: No such slot QHttp::ReceiveResponseHeader(QHttpResponseHeader)
Object::connect: No such slot QHttp::HttpRequestStarted(int)
Object::connect: No such slot QHttp::HttpRequestFinished(int,bool)


Is there a way to force MOC to know that the slot is actually in HttpSyncr and not the base class?


Steve

faldzip
5th September 2009, 06:30
Is there a way to force MOC to know that the slot is actually in HttpSyncr and not the base class?
yes, use Q_OBJECT macro in your class.

stevey
5th September 2009, 12:12
Well far out and golly jee wizz!
Thanks for that, I forgot about the illusive macro of doom.

It didn't occur to me that I'd need it in a subclass, but that's only header files of course. The subclass still needs to registered, all makes sense now.

Thanks again.

Steve