Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: How to display a Messagebox when you are within a function?

I'm developing using the Qt Nokia SDK.

I'm having trouble displaying the buttons of a MessageBox, when trying to display a messagebox within a function. If i try to display it within the main window, there is no problem showing the buttons.

The mainwindow consist of a QStackWidget which holds different widgets.

Here is the code that works in main window:

QMessageBox msgBox;
msgBox.setText("Name");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard |
                          QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();

Here is the function and code that i run after receiving a response from a web request (The messagebox displays, but not the buttons.

void MainWindow::RequestReceived()
{
    QMessageBox *msgBox = new QMessageBox(this);
    msgBox->setText("Test");
    msgBox->setWindowModality(Qt::NonModal);
    msgBox->setInformativeText("Do you want to save your changes?");
    msgBox->setStandardButtons(QMessageBox::Save | QMessageBox::Discard | 
                               QMessageBox::Cancel);
    msgBox->setDefaultButton(QMessageBox::Save);
    int ret = msgBox->exec();
}

Anyone got an idea of what is happening?

Thanks in advance!

like image 584
Ikky Avatar asked Mar 09 '11 15:03

Ikky


People also ask

How do I use QMessageBox?

To use the property-based API, construct an instance of QMessageBox, set the desired properties, and call exec() to show the message. The simplest configuration is to set only the message text property. QMessageBox msgBox; msgBox. setText("The document has been modified."); msgBox.


1 Answers

Try this code.It will help you.

QMessageBox Msgbox;
    int sum;
    sum = ui->textEdit->toPlainText().toInt()+ ui->textEdit_2->toPlainText().toInt();
    Msgbox.setText("sum of numbers are...."+sum);
    Msgbox.exec();
like image 123
Jayasankar.K Avatar answered Oct 17 '22 22:10

Jayasankar.K