Connect Signal to boolean variable

  • That is my idea (mnC is an object in a paralel thread)

    connect(mnC,SIGNAL(connected(bool)),this->isConnected,SLOT(append(bool) ,Qt::QueuedConnection);

    Please can somebody help me to make a direct connection between the boolean "isConnected" in MainWindow and the signal "connected" in thread?

    Thanks in advance

  • @yczo Why to complicate things? Just connect connected signal to a slot in "this" object which will set isConnected to the value passed via connected signal.

  • Qt Champions 2018

    @yczo You cannot connect a signal to a variable. Signals are connected to slots (which are C++ methods).
    As @MartinD said add a slot with a bool parameter to your class and connect the signal to that slot. In the slot you then set your variable.

  • Thank you very much all

  • Moderators

    @yczo Well you can use C++11 features. Instead of creating a slot you can do:

    connect(mnC, &MNCClass::connected, [=](const bool status){
         isConnected = status;

    P.S: I don't know name of class which contains connected so used MNCClass. Change it to your actual classname.

Log in to reply

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