Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved Connect Signal to boolean variable

    General and Desktop
    4
    5
    3729
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • yczo
      yczo last edited by

      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

      M jsulm p3c0 3 Replies Last reply Reply Quote 0
      • M
        MartinD @yczo last edited by MartinD

        @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.

        1 Reply Last reply Reply Quote 2
        • jsulm
          jsulm Lifetime Qt Champion @yczo last edited by

          @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.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 3
          • yczo
            yczo last edited by

            Thank you very much all

            1 Reply Last reply Reply Quote 1
            • p3c0
              p3c0 Moderators @yczo last edited by

              @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.

              157

              1 Reply Last reply Reply Quote 5
              • First post
                Last post