开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜