Results 1 to 2 of 2

Thread: Testing modal dialogs with QTestLib

  1. #1
    Join Date
    May 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Post Testing modal dialogs with QTestLib

    I haven't seen this discussed elsewhere, so I thought others might find it useful to know this.

    I have an app (basically just one top level Widget) that puts up a modal QMessageBox at one point. I am the testing my Widget with QTestLib (env: Qt 4.6.2 and Windows). My problem was how to get aQTest::KeyClick() delivered to the modal dialog from a test function.

    The thing is that when launching a modal dialog using either the static QMessageBox::information() function, or by calling exec() on a QMessageBox object, the UI (thread) is blocked and the test function can't call KeyClick() before the user dismisses the modal dialog manually - which means that user interaction is needed and the test cannot be run fully automatically. This is not what I wanted.

    However, I found out that if my widget under testing launches the modal dialog with QMessageBox::open(), the test function will continue running and it can dismiss the dialog by calling QTest::KeyClick() on it (I am using qApp->activeModalWidget() to get a pointer to the dialog). So, the test is now fully automatic!

    This works for me. But I am interested to hear if there are other ways to deal with this kind of problem?
    Last edited by bitflyer; 1st June 2010 at 13:48.

  2. #2
    Join Date
    May 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Testing modal dialogs with QTestLib

    Hi, I dont know if Your problem is exists yet or not, I found this solution:

    Qt Code:
    1. void MyTest::testPasswordDialog()
    2. {
    3. QTimer::singleShot(500, this, SLOT(TimeOut()));
    4. QVERIFY(functionThatProducesMessageBox());
    5. }
    6.  
    7. void MyTest::TimeOut()
    8. {
    9. QWidgetList allToplevelWidgets = QApplication::topLevelWidgets();
    10. foreach (QWidget *w, allToplevelWidgets) {
    11. if (w->inherits("QMessageBox")) {
    12. QMessageBox *mb = qobject_cast<QMessageBox *>(w);
    13. QTest::keyClick(mb, Qt::Key_Enter);
    14. }
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Testing Qt-Software with a GUI Testing Tool
    By nightghost in forum Qt Programming
    Replies: 8
    Last Post: 22nd February 2012, 07:43
  2. qtestlib
    By Jordan in forum Qt Programming
    Replies: 7
    Last Post: 28th September 2010, 11:47
  3. GUI Event testing using QTestLib
    By vels in forum Qt Programming
    Replies: 3
    Last Post: 23rd April 2010, 11:31
  4. testing with QTestLib
    By hyling in forum Qt Programming
    Replies: 2
    Last Post: 12th July 2007, 20:37
  5. screen number and modal dialogs
    By high_flyer in forum Qt Programming
    Replies: 18
    Last Post: 22nd June 2007, 18:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.