Can't receive signal from different thread if event(..) is redefined



  • Hello,
    Code is specially simplified. the construction like below doesn't works i.e. TestWidget doesn't receives signal; but if we comment bool Event(QEvent* event); everything works fine. Is it known bug or my code is wrong? Signals from buttons and i.e. works fine.

    @class TestWidget : public QWidget {
    Q_OBJECT
    public:
    TestWidget(QWidget* parent):QWidet(parent)
    {
    TestThread* t = new TestThread;
    connect(t,SIGNAL(test_signal),this,SLOT(test_slot));
    t->start();
    }
    private slots:
    void test_slot();
    protected:
    bool event(QEvent* event){return false;}
    }

    QTestThread: public QThread
    {
    Q_OBJECT;
    public:
    QThread(QObject* parant=0):QThread(parent){}
    protected:
    void run()
    {
    emit test_signal();
    }
    signals:
    void test_signal();
    }@



  • You just ignore every event for your widget.

    If you do not want to handle it on your own (or ignore entirely for your widget), you must delegate the processing back to the base class:

    @
    bool event(QEvent *e)
    {
    return QWidget::event(e);
    }
    @



  • Queued slot invocations use an event built behind the scenes by Qt (QEvent::Metacall). Therefore, your event() implementation MUST call the base class for event types you aren't interested in.



  • ... and again with the double post :)



  • o, I see. Thank you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.