Is there in Qt something like Form.onChange
in Delphi?
I found some changeEvent
method but when I wrote connect
connect(this, SIGNAL(this->changeEvent),this, SLOT(checkIfSomethingChanged()));
and tried to check it like that
void importdb_module::checkIfSomethingChanged(){
QMessageBox::information(0, "", "Test");
}
I realized that it not works.
I want to check some condition everytime when something changed in my form, how to do that?
The changeEvent slot is a virtual, protected function found in QWidget. Therefore, if you inherit from QWidget or any QWidget derived class, you'll be able to override that 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 wanted to know outside of the event that the form has been changed, you can add a signal to the form and emit it from the changeEvent to pass the event on: -
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 Qt 5 connect syntax: -
connect(myFormObject, &MyForm::FormChanged, someclassObject, &SomeClass::HandleFormChanged);
This cannot work, because you mixed up two concepts: events and signal/slots. To make it work, you need to override your class' changeEvent()
virtual function. Something like this:
void MyWidget::changeEvent(QEvent *event)
{
QMessageBox::information(0, "", "Test");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With