QMessage box signal and slot
-
is there any way to connect QMessageBox ok button clicked signal to a slot in another class
-
Hi and welcome to devnet,
If you are not using the static methods, then yes it is
-
hi and thank you,I wanted to call a slot in another class when ever QMessageBox Yes Button is clicked and I am not using static methods.Icouldnt figure out how
-
Use QMessageBox::button to retrieve the correct button and connect it accordingly
-
I tried like this but didnt work
connect(anotherclass->deleteMsgBox.button(QMessageBox::Yes),SIGNAL(clicked()),this,SLOT(repaint())); -
Hi and welcome to devnet,
In that case I suggest to use signal forwarding
- create a SIGNAL in the
anotherClass
- connect the message box signal to that signal
- connect the first signal to repaint
// AnotherClass.h class QMessageBox; class AnotherClass { Q_SIGNALS: void messageBoxOkClicked(); private: QMessageBox *deleteMsgBox; };
//AnotherClass.cpp AnotherClass::AnotherClass() { deleteMsgBox = new QMessageBox(this); connect(deleteMsgBox.button(QMessageBox::Yes), SIGNAL(clicked()), this, SIGNAL(messageBoxOkClicked())); }
//Widget.cpp connect (anotherClass, SIGNAL(messageBoxOkClicked()), this, SLOY(repaint()));
- create a SIGNAL in the
-
I tried this but it didnt work ,How can I connect two SIGNALS
-
you can connect 2 signals how I wrote.
can you post your code??
-
anotherclass.h
QMessageBox deleteMsgBox;
anotherclass.cpp:QGraphicsRectItem
anotherclass::delete()
{
deleteMsgBox.setText("Deleting state...");
deleteMsgBox.setInformativeText("Are you sure you want to delete this state?");
deleteMsgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
deleteMsgBox.setDefaultButton(QMessageBox::No);ret = deleteMsgBox.exec(); if(ret == QMessageBox::Yes){ ................. }
}
mainclass.cpp{mainclass::make()
{
connect(anotherclass->deleteMsgBox.button(QMessageBox::Yes),SIGNAL(clicked()),this,SLOT(repaint()));
}
mainclass::repaintAll()
{
..............
}
}