Signal do not work in derived class
I have such code:
class A : public QObject
{
Q_OBJECT
public:
explicit A(QObject *parent = 0) : QObject(parent)
{
connect(&http, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));
}
void sendRequest()
{
// ...
http.request(...);
}
public slots:
void httpDone(bool)
{
qDebug() << "recieved!";
}
protected:
QHttp http;
}开发者_Python百科;
class B : public A
{
//...
void getSomething()
{
sendRequest();
}
};
class C : public A
{
//...
void getSomething()
{
sendRequest();
}
};
// and now do some stuff
B b;
C c;
b.getSomething();
c.getSomething();
And there is only one "recieved!" message in console from b. Why?
You can check if you have Q_OBJECT macro in all the derived classes.
精彩评论