Emit Signal when Variable Changes Value
-
I'd like to emit a signal when a int variable changes value. The value of the int variable comes from an external application so I have no control over it or when it will change.
I've read through the documentation and tried to implement the following:
@//From MainWindow.h header file:
//******************************//
signals:
void StateChangedFromActive();public slots:
void CheckState();
//*****************************//// FROM MainWindow.cpp function
////
QObject::connect(this, SIGNAL(StateChangedFromActive()), this, SLOT(CheckState()));
//////From MainWindow::CheckState function
////
void MainWindow::CheckState()
{
if(CNC_STATE != 4) //CNC_STATE is a global variable for prototyping
{
emit StateChangedFromActive();
ui->ModeButtonStation->setEnabled(true);
}
}
////@So, basically I want to set a QToolButton as enabled whenever the CNC_STATE global changes from 4. I haven't found an example that shows how to emit a signal from something that isn't a QWidget.
-
Hi retro_code.
First of all i didn’t understand how external app can change your variable without your permission.
But, if your class should support signal and slots you need inherit it from QObject. For example:
@class SomeClass: public QObject
{
Q_OBJECT
....
signals:
void StateChangedFromActive();public slots: void CheckState();
}@