emit Qt signal from non Qt Thread or ouside Qt main event loop with at 4.5

后端 未结 1 1592
猫巷女王i
猫巷女王i 2020-12-06 10:52

I\'m calling a emit signal1() from a non Qt thread. By non Qt thread I mean not from the GUI Event Loop and not from any QThread run() method or any QThread own

1条回答
  •  臣服心动
    2020-12-06 11:33

    What you need to make sure is that you use a queued connection to a from threads, as Qt cannot autmatically sense which object that belong to which thread ("thread affinity" is the term used in the documentation). You do this when connecting:

    connect(src, SIGNAL(signal-signature), dest, SLOT(slot-signature), Qt::QueuedConnection);
    

    That will result in the signal being put on the event loop of the destination, and the slot being called when its thread is running (i.e. its event loop).

    0 讨论(0)
提交回复
热议问题