Results 1 to 11 of 11

Thread: Refresh application GUI after running external application

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Refresh application GUI after running external application

    Why do you think you need to explicitly redraw all widgets? Qt handles this as long as you let control return to the event loop. Your current code, which blocks the UI thread until the external process has finished executing, is inelegant because it prevents the user from interacting with your application, and the widgets are not updated. However, if you return to the event loop after the external process has finished executing, the widgets should be updated automatically.

    Now, if you want the UI to remain responsive while the external process is running, you need an event loop to be running. Instead of calling QProcess::waitForFinished(), you could connect QProcess::finished() to a slot, then start the process and return to the event loop. Your slot will be executed after the external process has finished executing.

  2. #2
    Join Date
    Jun 2015
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Refresh application GUI after running external application

    Quote Originally Posted by anda_skoa View Post
    Well, it is usually very bad to block event processing of a UI application.
    Do you have a specific requirement for that?

    Cheers,
    _
    Quote Originally Posted by yeye_olive View Post
    Why do you think you need to explicitly redraw all widgets? Qt handles this as long as you let control return to the event loop. Your current code, which blocks the UI thread until the external process has finished executing, is inelegant because it prevents the user from interacting with your application, and the widgets are not updated. However, if you return to the event loop after the external process has finished executing, the widgets should be updated automatically.

    Now, if you want the UI to remain responsive while the external process is running, you need an event loop to be running. Instead of calling QProcess::waitForFinished(), you could connect QProcess::finished() to a slot, then start the process and return to the event loop. Your slot will be executed after the external process has finished executing.
    See attached image when I launch my external application without blocking the main app. I get the following:
    Attachment 11255
    alternative link to image
    With the above code I am trying to prevent this occurring.

    Also, when using the external application, the user should not be interacting with the main application so I felt that waiting for the external application to finish was the best option.

    I am open to any/all suggestions on how to achieve this in a better way.
    Thanks
    Last edited by evanol; 6th July 2015 at 12:17.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Refresh application GUI after running external application

    As yeye_olive wrote, you don't need any special widget updating, just return from the slot.

    I would still not artificially freeze the application.

    The option that is closest to your current code is to use a QEventLoop instance and connect the process' finished() signal to the lop's quit() slot.
    Then you run exec() with the flag to exclude user input.

    Additionally, as a visual clue for the user, I would disable the UI before running the nested loop and re-enable it after exec() returns.

    Another option is to use a modal dialog.

    Cheers,
    _

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Refresh application GUI after running external application

    I cannot download the attachment in your last post. I get an error 'Invalid Attachment specified' when I try to do so.

    Globally preventing user interaction is frowned upon, because you do not even let the user close the application. If you want to prevent interaction with specific widgets, call QWidget::setEnabled(false).

    Nevertheless, if you insist on preventing user interaction, you could still run a local QEventLoop with the QEventLoop::ExcludeUserInputEvents flag.

Similar Threads

  1. Closing an external application with qt
    By Capton in forum Newbie
    Replies: 1
    Last Post: 19th June 2013, 23:45
  2. embed qt exe in external application
    By rattanas in forum Newbie
    Replies: 0
    Last Post: 5th May 2013, 07:59
  3. Replies: 4
    Last Post: 19th November 2012, 14:35
  4. How to control an external application?
    By lixo1 in forum Qt Programming
    Replies: 4
    Last Post: 25th September 2009, 21:29
  5. Replies: 12
    Last Post: 29th February 2008, 13:35

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.