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. How to connect a bool flag with a widget enable bool

How to connect a bool flag with a widget enable bool

Scheduled Pinned Locked Moved Solved General and Desktop
connectflag
7 Posts 6 Posters 3.4k Views
  • 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.
  • V Offline
    V Offline
    vasu_gupta
    wrote on 7 Sept 2017, 11:18 last edited by
    #1

    I have a button save as and i want it to active if and only if a bool edit is true ,in case this bool edit is again resetted save as option again becomes disable.

    How to do this

    R 1 Reply Last reply 7 Sept 2017, 11:24
    0
    • V vasu_gupta
      7 Sept 2017, 11:18

      I have a button save as and i want it to active if and only if a bool edit is true ,in case this bool edit is again resetted save as option again becomes disable.

      How to do this

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 7 Sept 2017, 11:24 last edited by raven-worx 9 Jul 2017, 11:25
      #2

      @vasu_gupta
      see Qt's signals/slots concept

      QObject::connect( checkBox, &QCheckBox::toggled, saveBtn, &QPushButton::setEnabled );
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      V 1 Reply Last reply 7 Sept 2017, 12:46
      4
      • R raven-worx
        7 Sept 2017, 11:24

        @vasu_gupta
        see Qt's signals/slots concept

        QObject::connect( checkBox, &QCheckBox::toggled, saveBtn, &QPushButton::setEnabled );
        
        V Offline
        V Offline
        vasu_gupta
        wrote on 7 Sept 2017, 12:46 last edited by
        #3

        @raven-worx i m not using a checkbox but a simple boolean variable

        J T 2 Replies Last reply 7 Sept 2017, 12:56
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 7 Sept 2017, 12:54 last edited by
          #4

          You can do
          button->setEnabled(Mybool);

          You cannot bind a variable to widget as such. Not with connect.

          How is this "bool edit" altered ?

          1 Reply Last reply
          1
          • V vasu_gupta
            7 Sept 2017, 12:46

            @raven-worx i m not using a checkbox but a simple boolean variable

            J Online
            J Online
            J.Hilk
            Moderators
            wrote on 7 Sept 2017, 12:56 last edited by J.Hilk 9 Jul 2017, 13:39
            #5

            @vasu_gupta

            #include <QObject>
            class booleanWithSignal : public QObject
            {
               Q_OBJECT
            
            public:
            void setTrue(){
                if(b != true)
                    emit changed(true);
                b = true;
            }
            
            void setFalse(){
                if(b != false)
                    emit changed(false);
                b = true;
            }
            
            const bool &state(){return b;}
            
            signals:
            void changed(bool state);
            
            private:
            bool b = false;
            
            }
            
            // in your ui-class
            booleanWithSignal allowSave;
            connect(&allowSave, &booleanWithSignal::changed,mySaveBtn, &QPushButton::setEnabled);
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            3
            • V vasu_gupta
              7 Sept 2017, 12:46

              @raven-worx i m not using a checkbox but a simple boolean variable

              T Offline
              T Offline
              Taz742
              wrote on 7 Sept 2017, 13:05 last edited by
              #6

              @vasu_gupta said in How to connect a bool flag with a widget enable bool:

              @raven-worx i m not using a checkbox but a simple boolean variable

              and what are you using?

              Do what you want.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dheerendra
                Qt Champions 2022
                wrote on 7 Sept 2017, 13:37 last edited by
                #7

                as it already suggested by other in the group, please go through signals/slots. Try few examples with how signals/slots work. This should give good info to achieve your use case.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                1 Reply Last reply
                0

                3/7

                7 Sept 2017, 12:46

                • Login

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