Is there an onChange event in Qt forms?

Is there something like Form.onChange in Delphi in Qt?

I found some changeEvent method, but when I wrote connect connect(this, SIGNAL(this->changeEvent),this, SLOT(checkIfSomethingChanged()));

and tried to check it that way

 void importdb_module::checkIfSomethingChanged(){ QMessageBox::information(0, "", "Test"); } 

I realized that it does not work.

I want to check some condition every time something changes in my form, how to do it?

+7
c ++ events qt delphi
source share
2 answers

The changeEvent slot is a virtual, secure function found in a QWidget. Therefore, if you inherit a QWidget or any QWidget-based class, you can override this function. For example: -

 class MyForm : public QWidget { protected slots: virtual void changeEvent(QEvent * event); } void MyForm::changeEvent(QEvent* event) { // Do something with the event } 

If you want to know outside the event that the form has changed, you can add a signal to the form and emit it from changeEvent to pass the event: -

 class MyForm : public QWidget { signals: void FormChanged(QEvent* event); protected slots: virtual void changeEvent(QEvent * event); } void MyForm::changeEvent(QEvent* event) { emit FormChanged(event); } 

Now connect another class to the new signal using the Qt 5 connect syntax: -

 connect(myFormObject, &MyForm::FormChanged, someclassObject, &SomeClass::HandleFormChanged); 
+4
source share

This may not work because you are mixing two concepts: events and signal / slots. For it to work, you need to override the virtual function of the changeEvent() class. Something like that:

 void MyWidget::changeEvent(QEvent *event) { QMessageBox::information(0, "", "Test"); } 
+2
source share

All Articles