Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't receive signal from different thread if event(..) is redefined
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    heorhiy
    wrote on last edited by
    #1

    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();
    }@

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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);
      }
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3

        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.

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

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          ... and again with the double post :)

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

          1 Reply Last reply
          0
          • H Offline
            H Offline
            heorhiy
            wrote on last edited by
            #5

            o, I see. Thank you.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved