February 6, 2011

heorhiy heorhiy
Lab Rat
9 posts

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.

  1. class TestWidget : public QWidget {
  2.   Q_OBJECT
  3. public:
  4.    TestWidget(QWidget* parent):QWidet(parent)
  5.    {
  6.        TestThread* t = new TestThread;
  7.        connect(t,SIGNAL(test_signal),this,SLOT(test_slot));  
  8.        t->start();
  9.    }
  10. private slots:
  11.       void test_slot();
  12. protected:
  13.       bool event(QEvent* event){return false;}
  14. }
  15.  
  16. QTestThread: public QThread
  17. {
  18.     Q_OBJECT;
  19. public:
  20.     QThread(QObject* parant=0):QThread(parent){}
  21. protected:
  22.   void run()
  23.   {
  24.      emit test_signal();
  25.   }
  26. signals:
  27.     void test_signal();
  28. }

4 replies

February 7, 2011

Volker Volker
Ant Farmer
5428 posts

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:

  1. bool event(QEvent *e)
  2. {
  3.     return QWidget::event(e);
  4. }

February 7, 2011

peppe peppe
Ant Farmer
1026 posts

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.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

February 7, 2011

peppe peppe
Ant Farmer
1026 posts

… and again with the double post :)

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

February 7, 2011

heorhiy heorhiy
Lab Rat
9 posts

o, I see. Thank you.

 
  ‹‹ QT open source projects      Syntax Question ››

You must log in to post a reply. Not a member yet? Register here!