Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Does your QThread run the event loop? It has to do it to receive signals:</p> <blockquote> <p>Queued Connection The slot is invoked <strong>when control returns to the event loop</strong> of the receiver's thread. The slot is executed in the receiver's thread.</p> </blockquote> <p>Basically queued connection works the following way:</p> <ol> <li>The originator issues a signal.</li> <li>Qt creates an event and posts it into the receiver event queue.</li> <li>The receiver goes through its event queue, picks up the events and dispatches the signals into the connected slots.</li> </ol> <p>Hence if you do not run the event queue, the signals are posted but your thread will never receive them.</p> <p>So basically your thread should do some initialization in run() but then call exec() and pass it to Qt.</p> <p>If your thread also needs to run some periodic operations besides checking for signals, you can do that by using QTimer::singleShot timers posting signals to the same thread.</p> <p>See <a href="http://qt-project.org/doc/qt-4.8/threads-qobject.html#signals-and-slots-across-threads" rel="nofollow">http://qt-project.org/doc/qt-4.8/threads-qobject.html#signals-and-slots-across-threads</a></p> <p>PS. If you pass the pointers via queued connections, the pointer must be valid until the signal is processed, which may be after your function which posted the signal existed. A common error is to post signals with strings as a parameters which are stored in a local char[] buffer. At the moment the buffer is accessed the original function is finished, and the string is already gone. Those errors depend on thread scheduling and therefore hard to debug. If you pass the pointers via queued connection, they must be heap-allocated and the callee must be responsible to free them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload