Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:55:52+00:00 2026-05-30T17:55:52+00:00

I am trying to write a unit test for a GUI application using the

  • 0

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 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(). Therefore, I tried creating a QThread that performs the interaction. However, this did not help.

Things I already tried (all performed from within the “interaction helper” thread):

  1. Send key clicks using QTest::keyClicks()
    • Results in error message “QCoreApplication::sendEvent(): Cannot send events to objects owned by a different thread”
  2. Post QKeyEvents using QCoreApplication::postEvent()
    • Doesn’t work, i.e. nothing happens. I guess because the events end up in the event loop of the thread that owns the dialog, which will not be reached until the dialog is closed and exec() returns. See Edit below
  3. Invoking Slots on the dialog using QMetaObject::invokeMethod()
    • Doesn’t work, i.e. nothing happens. I guess for the same reason as postEvent() doesn’t work. See Edit below

So the question is: Is there any way to interact programmatically with a modal dialog that was opened using the exec() method?

Edit: Actually, method 3 is working. The problem was a different one:
I passed the arguments to invokeMethod() to the “interaction helper” thread and for some reason, accessing the arguments did not work from that thread (I got no SEG errors but they were simply empty).
I guess that method 2 is also working and I simply had the same problem as with method 3 but I didn’t test that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:55:53+00:00Added an answer on May 30, 2026 at 5:55 pm

    The solution I use in command line applications which use Qt libraries meant for GUIs is the singleShot, as this answer alludes. In those cases it looks like this:

    QCoreApplication app(argc, argv);
    
    // ...
    
    QTimer::singleShot(0, &app, SLOT(quit()));
    return app.exec();
    

    So in your case I imagine it would look something like this:

    QDialog * p_modalDialog = getThePointer(); // you will have to replace this with
                                               // a real way of getting the pointer
    
    QTimer::singleShot(0, p_modalDialog, SLOT(accept()));
    
    p_modalDialog->exec(); // called somewhere else in your case
                           // but it will be automatically accepted.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any ideas on this one? I'm trying to write a unit test that will
I am trying to write a unit test using .NET 4 to ensure that
I'm new to C# and trying to write a simple GUI Unit Test with
I'm trying to write a unit test for a module that will give me
I'm trying to write a unit test that will loop through all action methods
I am trying to write a unit test for my one controller to verify
I'm trying to write a unit test that will raise an event on a
I'm trying to write a unit test for a piece of code that generates
I am trying to write a unit test for a client server application. To
Trying to write Unit test for Silverlight 4.0 using Moq 4.0.10531.7 public delegate void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.