Results 1 to 2 of 2

Thread: How to use QProcess to open an URL

  1. #1
    Join Date
    Sep 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to use QProcess to open an URL

    Hi ,
    please suggest the way to use QProcess to open an URL (internet browser).

    Thanks,
    Sam

  2. #2
    Join Date
    Jun 2008
    Location
    Germany/Belarus/Sweden
    Posts
    53
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: How to use QProcess to open an URL

    best way:
    Qt Code:
    1. QDesktopServices::openUrl(QUrl(tr("http://discussion.forum.nokia.com/forum/forumdisplay.php?f=40")));
    To copy to clipboard, switch view to plain text mode 


    bad way:
    Qt Code:
    1. #ifdef Q_WS_WIN
    2. result = int(ShellExecuteW(HWND_TOP,
    3. 0,
    4. rUrl.ucs2(),
    5. 0,
    6. 0,
    7. SW_SHOWNORMAL)) > 32;
    8. #else
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // Try a range of browsers available on UNIX, until we (hopefully)
    2. // find one that works. Start with the most popular first.
    3.  
    4. QProcess process;
    5. bool process_started = false;
    6. process.setArguments(QStringList() << "netscape" << rUrl);
    7.  
    8. process_started = process.start();
    9.  
    10. if (!process_started)
    11. {
    12. process.setArguments(QStringList() << "mozilla" << rUrl);
    13.  
    14. process_started = process.start();
    15. }
    16. if (!process_started)
    17. {
    18. process.setArguments(QStringList() << "firefox" << rUrl);
    19.  
    20. process_started = process.start();
    21. }
    22. if (!process_started)
    23. {
    24. process.setArguments(QStringList() << "konqueror" << rUrl);
    25.  
    26. process_started = process.start();
    27. }
    28. result = process_started;
    To copy to clipboard, switch view to plain text mode 
    Last edited by AcerExtensa; 14th September 2009 at 08:43.

Similar Threads

  1. Replies: 3
    Last Post: 25th August 2010, 12:39
  2. Open file without run again the program
    By avis_phoenix in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2009, 23:01
  3. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 12:53
  4. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  5. QProcess open all file -> url.dll,FileProtocolHandler
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2006, 17:07

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.