Test modal dialog with Qt Test

前端 未结 4 879
青春惊慌失措
青春惊慌失措 2021-01-05 09:34

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 modal dialog using exec() and I found

4条回答
  •  被撕碎了的回忆
    2021-01-05 10:15

    You can keep the interaction in the same thread by delaying its execution until the dialog event loop starts.

    For example just before the exec() call, you use either QTimer::singleShot with 0 as interval or QMetaObject::invokeMethod with connection type Qt::QueuedConnection to invoke the slot that needs to be executed while the dialog is shown.

提交回复
热议问题