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 8650297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:47:05+00:00 2026-06-12T13:47:05+00:00

Is there a safe way to use Qt without calling QApplication::exec()? I have a

  • 0

Is there a safe way to use Qt without calling QApplication::exec()?

I have a number of different objects that are carrying out long-lived processes on multiple resources (at least one of them is communicating with a web application server). I’m making a GUI application that prompts the user for input at the right time for these different processes. I’d like to have my ‘flow’ logic – the logic that determines what to do next – in one place and not in a GUI object like a dialog class. I was thinking that I could do something like this:

...

wait_dialog dlg;
dlg.setModal( false );
dlg.show(); // Should return...

netobject.start_long_lived_process_that_happens_on_other_thread( &completion_callback );
while ( !completion_callback_called() )
{
    qApp->processEvents();
    netobject.pump_callbacks();
    magically_avoid_busywait_while_still_servicing_qt_somehow();
}

dlg.hide();

...

Is this safe, from Qt’s point of view? Is there a ‘good’ way of implementing magically_avoid_busywait_while_still_servicing_qt_somehow()?

What I’m trying to accomplish here is to write our processing flow in the most explicit way possible. I’d like a single function that does this:

 show_a_non_modal_wait_dialog()

 start_some_processing_1()

 wait_for_processing_1_to_finish()

 dismiss_non_modal_wait_dialog()

 show_modal_input_dialog()

 if ( cancelled ) return

 show_a_non_modal_wait_dialog()

 start_some_processing_2()

 wait_for_processing_2_to_finish()

 dismiss_non_modal_wait_dialog()

 show_modal_input_dialog()

 if ( cancelled ) return

 ...

What I really want to avoid is kicking off and waiting for the processing inside Qt widgets and windows. Also, the processing objects themselves are entirely independent of Qt. I suppose what I’m trying to do is create a controller in a single function with a few helper callbacks and status variables.

  • 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-06-12T13:47:06+00:00Added an answer on June 12, 2026 at 1:47 pm

    What you want is an event loop other that the application’s main event loop. This can be done using the QEventLoop:

    wait_dialog dlg;
    dlg.setModal( false );
    dlg.show(); // Should return...
    
    QEventLoop loop;
    connect(&netobject, SIGNAL(done()), &loop, SLOT(quit()));
    netobject.start_long_lived_process_that_happens_on_other_thread();
    
    loop.exec(); // BLOCKING (non-busy) until quit() is called via the signal done()
    

    While this is (in my eyes) clean code, this requires your netobject class to be a QObject and implement a signal done() (which is also cleaner than providing callbacks).

    Now you can wrap this whole code in a function which will be a blocking call on itself, so it can return some results from your dialog if you want so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an external library that takes an IntPtr. Is there any safe way
Is there any way to play progressive videos that is not safe for streaming
Is there any proper way to make TH's functions safe if they use side
Is there any safe and standard compliant way to treat a C style array
Is there a way I can ask Visual source safe to get all the
Is there a way to export files/folders from Source Safe? (i.e. getting rid of
Is there any way to check if it is safe to delete record from
Is there any primitive data type that it's safe to not initialize? How about
Are there overall rules/guidelines for what makes a method thread-safe? I understand that there
In Mysql there is a compare operator that is a null safe: <=>. I

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.