Manuninho
Manuninho

Reputation: 31

Select QMessageBox stored as local variable for QTest

I'm trying to test with QTest a GUI application. I can access to all the UI elements across the ui_class.h. The problem is, that I've created several QMessageBox on the main program as local variable and I need them to use QTest::mouseClick() when anyone of them appears.

I'm trying to avoid to realocate those QMessageBox if possible, so I tried to get the Widgets with QApplication::topLevelWidgets() and QApplication::allWidgets(), but they were not working because I cannot find any QWidget which inheriths to QMessageBox. Neither is working QApplication::activeWindow() to make click (or press enter, I just wanna go further after clicking or pressing enter).

So, I would need to know how to select that QMessageBox stored as local variable on my GUI application I'm testing, to select it as QWidget.

My stored variables are QMessageBox::StandardButton and QMessageBox::warning

Thanks in advance for the help.

Upvotes: 0

Views: 95

Answers (2)

Manuninho
Manuninho

Reputation: 31

Well, after trying something else and getting another problem, the easiest workaround for this was to declare all the QMessageBox on the header function as public, so I can access them through the QTest class.
That's the problem of using static messages.

Upvotes: 0

eugesh
eugesh

Reputation: 111

Could you show more code, please? It's not clear: do you use

QMessageBox(QWidget *parent = nullptr)

constructor or something else. May be you might use obj->findChild<T>(name) or qobject_cast()? If you post your code I may try to test it.

Upvotes: 0

Related Questions