PDA

View Full Version : Presenting error messages in one window.



AndresBarbaRoja
17th June 2011, 16:42
Good day,
I need to create a non-modal dialog on which I can present error messages as they are received. The idea is to open a new window if I get an error and to add lines to the detailed description if any new error is reported while the dialog is still open.
I subclassed the QMessageBox to make it singleton and then the code that calls the window is something like this


void MainWindow::on_pushButton_clicked()
{
errWind = ErrorWindow::Instance();
errWind->setModal(false);
errWind->setText("Errores:");
QString msg = errWind->detailedText();
msg.append("ERROR\n");
errWind->setDetailedText(msg);
errWind->show();
// int ret = errWind->exec();
// if(ret==QMessageBox::Ok)
// errWind->setDetailedText("");
}

The commented code is there because I wan to clean the detailedText when the ok button is pushed, but the exec() makes the window modal and that does not work for me.
How can I clear the detailed text on Ok button pushed?
I already tried overloading the done() and the accepted() functions, but that does not worked for me.
Thanks in advance for any idea

Rachol
17th June 2011, 16:48
What about QMessageBox::clickedButton () ?

AndresBarbaRoja
17th June 2011, 17:05
Hmmm i fail to see how to use that function. I see the example, but i'm not sure about how to apply it

Added after 7 minutes:

Ok, this is what i have done and it seems to work. Can you see any problem with this method?

void MainWindow::on_pushButton_clicked()
{
errWind = ErrorWindow::Instance();
errWind->setModal(false);
errWind->setText("Errores:");
QString msg = errWind->detailedText();
msg.append("ERROR\n");
errWind->setDetailedText(msg);
errWind->show();
connect(errWind,SIGNAL(buttonClicked(QAbstractButt on*)),this,SLOT(clearErrors(QAbstractButton*)));
}

void MainWindow::clearErrors(QAbstractButton*)
{
errWind->setDetailedText("");
}

Thanks

Rachol
17th June 2011, 18:01
Yes it is perfectly fine if you have only 1 button. If you have 2 buttons, then use ButtonRole QMessageBox::buttonRole ( QAbstractButton * button ) const to check what button has been presssed