Results 1 to 4 of 4

Thread: How to detach a QProcess?

  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default How to detach a QProcess?

    I have created HTML help for my app (using the Helpinator product). I use this code to fir it off from a menu action:

    Qt Code:
    1. void MainWindow::onHelpUserManual()
    2. {
    3. QString helpIndexUrl = QCoreApplication::applicationDirPath() + "/htmlhelp/index.html";
    4. int result = QProcess::execute( "cmd.exe", QStringList() << "/c" << helpIndexUrl );
    5. if ( result < 0 )
    6. QMessageBox::warning( this, "Command failed", "Could not open user manual. Please open it using the Windows Start menu instead." );
    7. }
    To copy to clipboard, switch view to plain text mode 

    This works fine - if my browser (Firefox) is running, it opens a new tab and loads the help file into it. If it isn't running, it starts the browser and loads the help file.

    The problem is this: In the first case (browser already running), the call to QProcess::execute() returns immediately. In the second case (browser not running), the execute call does not return and so the program is frozen until I exit the browser.

    (Pause while I close the browser and test QProcess::startDetached())

    startDetached() does not work either. Bizarre behavior - in a debug build, startDetached() will run up a command window, which then starts the browser. In a release build, startDetached() results in a quick flash of the command window, then nothing. Doesn't matter whether the browser is running or not.

    How do I do this? I am at a loss to explain what I am observing.
    Last edited by d_stranz; 28th August 2015 at 01:58.

  2. #2
    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: How to detach a QProcess?

    startDetached() should work.

    Any reason you are launching this command instead of using QDesktopServices:penUrl()?

    Cheers,
    _

  3. The following 2 users say thank you to anda_skoa for this useful post:

    d_stranz (28th August 2015), Frdz (28th August 2015)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to detach a QProcess?

    Any reason you are launching this command instead of using QDesktopServices:: openUrl()?
    Lack of knowledge This sounds like a much better solution - I looked for something like this, but didn't know the right keywords.

    -- Edit - works like a charm! Thanks!

    Anyway, my brain woke me early this morning to tell me that if you want to open a file, you should make sure the file actually exists in the place where you are trying to open it. I had made a copy of the html help file in the debug output directory, but not in the release directory.

  5. #4
    Join Date
    Aug 2015
    Location
    Gdansk, Poland
    Posts
    21
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to detach a QProcess?

    Any reason you are launching this command instead of using QDesktopServicesenUrl()?
    Ouch, I was tought this class was fully deprecated, therefore I didn't read if there's some members still can be used. Thank you for having me realize it

Similar Threads

  1. Replies: 1
    Last Post: 3rd June 2013, 14:11
  2. Finding QwtPlot child item to detach it
    By Momergil in forum Qwt
    Replies: 2
    Last Post: 16th January 2013, 20:01
  3. how to detach Tab page from QTabWidget?
    By rajesh in forum Newbie
    Replies: 3
    Last Post: 30th May 2012, 17:20
  4. Replies: 1
    Last Post: 13th July 2011, 09:55
  5. detach only one qwt plot curve?
    By kja in forum Qwt
    Replies: 1
    Last Post: 3rd December 2010, 08:54

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.