How to connect a bool flag with a widget enable bool
-
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
-
@vasu_gupta
see Qt's signals/slots conceptQObject::connect( checkBox, &QCheckBox::toggled, saveBtn, &QPushButton::setEnabled );
-
@raven-worx i m not using a checkbox but a simple boolean variable
-
You can do
button->setEnabled(Mybool);You cannot bind a variable to widget as such. Not with connect.
How is this "bool edit" altered ?
-
#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);
-
@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?
-
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.