I am trying to write unit test for a GUI application using QTestLib. The problem is that one of the slots creates a modal dialog using exec() , and I did not find the ability to interact with the dialog.
The slots that create the dialogue are associated with a QAction. So the first problem is that the test blocks when I run QAction in the test, as this leads to the call to exec() . So I tried to create a QThread that does the interaction. However, this did not help.
Things I've already tried (they all run from the helper helper thread):
- Sending key clicks with
QTest::keyClicks()- The results in the error message "QCoreApplication :: sendEvent (): cannot send events to objects belonging to another thread"
- Publish QKeyEvents using
QCoreApplication::postEvent()Doesn't work, i.e. Nothing happens. I think because the events end in the event loop of the thread that owns the dialog that will not be reached until the dialog is closed and exec() returns. See "Editing below"
- Calling slots in a dialog using
QMetaObject::invokeMethod()Doesn't work, i.e. Nothing happens. I think for the same reason that postEvent() does not work. See "Editing" below
So the question is: is there a way to interact programmatically with the modal dialog that was opened using the exec() method?
Edit: Actually, method 3. The problem was different: I passed the invokeMethod() arguments to the "helper interaction" stream, and for some reason the access to the arguments did not work from this stream (I did not have SEG errors, but they were just empty). I assume that method 2 also works, and I had the same problem as with method 3, but I did not test this.
source share