Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to pass a variable from a one thread to main GUI thread



  • I am using following code

    QVariant myclass::Execute(QString command, QString xInfo)
    {
    QTimer::singleShot(0, this, SLOT(slotExecuteTcl()));
    return QVariant(true);
    }
    void myClass::executeTcl()
    {
    QString res;
    if ( Tcl_Eval(command, res) ) {

    }
    

    // return QVariant(res);

    }

    I want to pass command from ::Execute to executeTcl , since we move from one thread to GUI main thread could you please suggest how to move the variable from one thread to GUI main thread


  • Lifetime Qt Champion

    Hi
    You can make a new signal

    signals:
    void MyValue( QString );

    and in execute, emit it
    void myClass::executeTcl()
    { ...
    emit MyValue("somestring"); // or via variable
    }

    You have to have
    some slot in main connected to MyValue signal.


Log in to reply