Non-modal QMessageBox causing application to exit
-
I'm trying to display a non-modal QMessageBox inside a QUdpSocket readyRead() slot. This is in response to a particular message received via UDP. I'm creating the QMessageBox as follows:
@ static std::unique_ptr<QMessageBox> msgBox;
msgBox.reset(new QMessageBox()); msgBox->setWindowTitle("Some title"); msgBox->setText("Some question?"); msgBox->setStandardButtons(QMessageBox::Ok|QMessageBox::Ignore); msgBox->setModal(false); msgBox->setWindowFlags(msgBox->windowFlags() | Qt::WindowStaysOnTopHint); msgBox->show(); connect(msgBox.get(), SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(msgBoxClosed(QAbstractButton*)));
@
The msgBoxClosed() function is currently empty, but I intend to react to which button is clicked. Upon clicking either Ok or Ignore, the application exits most of the time. If it doesn't happen the first time, it certainly does the second.
This works fine if I make the QMessageBox modal, but the application needs to continue processing events while it waits for a response.
Any ideas?
This is the first time I've used Qt, so the problem is probably obvious to you guys. -
Why do you need to create a unique_ptr?
@ static std::unique_ptr<QMessageBox> msgBox;
msgBox.reset(new QMessageBox());@
Maybe you can just make it like this:
@QMessageBox *msgBox = new QMessageBox();@