Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connect Signal to boolean variable
Forum Updated to NodeBB v4.3 + New Features

Connect Signal to boolean variable

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 4.6k Views 1 Watching
  • 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.
  • Y Offline
    Y Offline
    yczo
    wrote on 18 May 2016, 15:15 last edited by
    #1

    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 J P 3 Replies Last reply 18 May 2016, 15:31
    0
    • Y yczo
      18 May 2016, 15:15

      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 Offline
      M Offline
      MartinD
      wrote on 18 May 2016, 15:31 last edited by MartinD
      #2

      @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
      2
      • Y yczo
        18 May 2016, 15:15

        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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 19 May 2016, 04:59 last edited by
        #3

        @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
        3
        • Y Offline
          Y Offline
          yczo
          wrote on 23 May 2016, 11:55 last edited by
          #4

          Thank you very much all

          1 Reply Last reply
          1
          • Y yczo
            18 May 2016, 15:15

            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

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 23 May 2016, 12:07 last edited by
            #5

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

            2/5

            18 May 2016, 15:31

            • Login

            • Login or register to search.
            2 out of 5
            • First post
              2/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved