Send Var to Main thread

  • Hi
    How can I send Variable or data from worker Thread (or other Thread implementation ) to Gui (Main Thread)?
    I do vice versa (Gui Thread to other thread ) with signal/slot.

  • @Alexanov
    Thats exactly the way to do it:

       void sendData(QVariant value);
       void getData(QVariant value);
    //connect the 2
    connect(ObjectInThread1, &myThreadedClass1::sendData, ObjectInThread2, &mainThreadClass::getData, Qt::QueuedConnection);

    the with5th paramter is optional, but either leave it open aka Qt::AutoConnection or write Qt::QueuedConnection

  • Moderators

    @Alexanov There is no difference whether from main thread to other thread or from other thread to main thread.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.