Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In Qt you cannot (or should not) call any GUI functions in another thread than the main thread. What you can do is emit a signal in the worker thread and receive it in the main thread.</p> <p>For example if you after creating the thread just call</p> <pre><code>connect(thread, SIGNAL(newText(QString)), lineEdit, SLOT(setText(QString))); </code></pre> <p>By default this will establish a connection of type <code>Qt::AutoConnection</code>. Whenever you emit the signal in the same thread where the receiver lives, it is equivalent to a simple function call. But when you emit that signal in another thread (like your new thread), it gets queued and is then delivered when the main thread is scheduled again and continues with its event loop and therefore the slot function will always be called in the thread where the receiver lives. But keep sure that you declare the signal with a value parameter (no pointer or reference), so you really get a copy of the <code>QString</code> and not a pointer/reference to the thread's string (which might already have been overwritten by the thread).</p> <pre><code>... signals: void newText(QString); ... </code></pre> <p>You can also configure the connection so that the thread waits (blocks) after emiting until the receiver is finished with handling the signal (has returned from the slot function), by using <code>Qt::BlockingQueuedConnection</code> as connection type. But in your case this should not be neccessary.</p> <p>For more information look at Qt's <a href="http://doc.qt.nokia.com/4.7/threads.html" rel="nofollow">excelent documentation</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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