Results 1 to 2 of 2

Thread: Using QtScript to interact with blocking modal dialogs

  1. #1
    Join Date
    Jan 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Using QtScript to interact with blocking modal dialogs

    Hello,

    I am attempting to use QtScript to perform GUI testing. However, in my application, there are modal dialogs that block script execution when invoked, such as the Tools > Options dialog. How can I control these dialogs (click their buttons, etc.) through QtScript?

    I have tried several approaches:
    1. Run the script engine in a separate thread: This creates other issues, such as having to delay after emitting a button's clicked() signal, in order to stay in sync with the the main thread.
    2. Separate the invocation of the modal dialog in an entirely new thread: I get a runtime error:
      QObject::setParent: Cannot set parent, new parent is in a different thread
      QObject: Cannot create children for a parent that is in a different thread.
      (Parent is QApplication(0x7fff4474fe10), parent's thread is QThread(0x6d7640), current thread is ScriptFuncThread(0x76d9c0)
    3. Separate the QtScript that interacts with the dialog into a new thread. This works some of the time; however, occasionally, I get a segmentation fault. (I did some googling and it may be due to that QScriptEngine is not thread-safe - http://www.qtcentre.org/threads/2713...current-script)
    4. Refactor the dialog C++ code to call setModal(true) and then show() instead of exec(), and then connect a handler slot to the dialog's finished(int) signal. This works, but I would rather not refactor the existing C++ code for all my dialogs from


    Qt Code:
    1. int result = dialog_widget->exec();
    2. dialog_widget->handleResult(result);
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. connect(dialog_widget, SIGNAL(finished(int)), dialog_widget, SLOT(handleResult(int)));
    2. //...
    3. dialog_widget->setModal(true);
    4. dialog_widget->show();
    To copy to clipboard, switch view to plain text mode 

    Could there be a way to send events from the main window event loop to the QDialog's local event loop?

    This is not a problem with non-modal dialogs; I can use QtScript to interact with them without trouble.

    Thank you.

  2. #2
    Join Date
    Mar 2008
    Location
    Marslev, Denmark
    Posts
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Using QtScript to interact with blocking modal dialogs

    My own solution would be your #4.

    But, are you sure the connection from your script signals are done with queued connections?

    Another option is to have a dispatcher QObject between your script code and the dialog. This object receives the signals from the script and calls postEvent(dialog-object, someevent). You have to implement custom events for this to work, though.
    Bo Thorsen, Viking Software
    Qt applications on Linux and Windows

Similar Threads

  1. Testing modal dialogs with QTestLib
    By bitflyer in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2013, 15:34
  2. Creating modal dialogs
    By Luc4 in forum Qt Programming
    Replies: 8
    Last Post: 17th June 2010, 10:35
  3. Replies: 1
    Last Post: 19th March 2010, 10:19
  4. modal dialog blocking problem...
    By photonmaster in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2008, 09:49
  5. screen number and modal dialogs
    By high_flyer in forum Qt Programming
    Replies: 18
    Last Post: 22nd June 2007, 18:48

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.