c++ - Check for a QMessageBox and close it -
i need automate gui tests in c++ qt using qtest (in eclipse) have given function adds tabs tabwidget (up max 9) , if try open 10th tab, qmessagebox appears:
qmessagebox::critical(this, "max9", tr("only maximum of 9 tabs can opened.\n")); because whole menu "add tab" function , private, had access method using slots , signals testclass.
now question is, there way can check whether there qmessageboxes open , if yes, automatically close them?
edit: solved put vahancho's solution method (closemessageboxes) , i've created timer in testmethod calls closemessageboxes() method then:
qtimer *timer = new qtimer(this); connect(timer, signal(timeout()), this, slot(closemessageboxes())); timer->start(5000); there multiple messageboxes appearing closing after 5 seconds.
i think, can find message boxes top level widgets, , close them 1 one:
qwidgetlist topwidgets = qapplication::toplevelwidgets(); foreach (qwidget *w, topwidgets) { if (qmessagebox *mb = qobject_cast<qmessagebox *>(w)) { qtest::keyclick(mb, qt::key_enter); } } however problem message box modal dialog , blocks main event loop. need find way execute code above after message box appeared.
Comments
Post a Comment