3

I am trying to write a unit test for a GUI application using the QTestLib. The problem is that one of the slots creates a file dialog using exec() and I found no possibility to interact with the dialog.

The slots which creates the dialog is connected to a QAction. So the first problem is that the test blocks when I trigger the QAction in the test since this results in the call to exec().

Here is my code snip

            QActoin* currentActoin;
            if(currentAction->text() == action)
            {
               currentAction->trigger();
               ..........
            }

Here once i triggered the action, it opens the file dialog which needs manual intervention to return to program. How can i come back to test code without manual intervention? i.e How can i get the handler (pointer) to the file dialog? How can set value for the file dialog?

Anbu
  • 91
  • 7
  • just as a rough guess: before calling exec() function, connect single shot timer to a slot which will simulate gui events (here example http://qt-project.org/doc/qt-4.8/qtestlib-tutorial3.html). – Nikita Aug 29 '14 at 22:46
  • When the program encounter currentAction->trigger(), it invokes the respective slot ( i.e populate the file dialog ). Connecting single shot timer is not helping me here. – Anbu Aug 30 '14 at 10:54
  • Don't use `exec()`, use `open()` or `show()` instead. – Kuba hasn't forgotten Monica Aug 30 '14 at 20:17
  • Create a wrapper function for interacting with `QFileDialog`. When test mode is enabled, the wrapper should not show the dialog but return programmed value instead. – Pavel Strakhov Aug 30 '14 at 23:23
  • Just observed, there is no exec() in the file dialog definition. i.e There are no event loops. Still i couldn't come out using QTimer. – Anbu Sep 01 '14 at 19:35
  • @nikitoz you are correct. I have used single shot timer before calling the currentAction->trigger();. It is working fine. Thanks all for the reply. – Anbu Sep 02 '14 at 06:10

0 Answers0