Results 1 to 8 of 8

Thread: add link that open web browser on unix

  1. #1
    Join Date
    Oct 2006
    Posts
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default add link that open web browser on unix

    hi
    I wish to open a web browser in unix ( mozilla) from QT .
    I saw that this question was asked here before and i used the answer in mu code .
    BUT
    it doesn't work for me. the process crash ( normalExit return 0 ) and no browser is open.

    How can i figure out why it does not work ??
    more details :
    I am working on sun OS
    which i am loged in using the rlogin command
    the DISPLAY env is set correctlly in my ~/.cshrc file.

    here is the code that i copy from this forum :
    and what does Q_UNUSED(this) mean ?

    Qt Code:
    1. bool result = false;
    2. QUrl rUrl("http://www.cnn.com");
    3. QString sUrl = rUrl;
    4. QApplication::setOverrideCursor(Qt::BusyCursor);
    5.  
    6. Q_UNUSED(this);
    7. // Try a range of browsers available on UNIX, until we (hopefully)
    8. // find one that works. Start with the most popular first.
    9. QProcess process;
    10. bool process_started = false;
    11.  
    12. process.setArguments(QStringList() << "mozilla" << sUrl );
    13. process_started = process.start();
    14.  
    15. QApplication::restoreOverrideCursor();
    16.  
    17. return;
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 24th January 2009 at 14:41. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: add link that open web browser on unix

    Quote Originally Posted by asafb View Post
    How can i figure out why it does not work ??
    You create QProcess instance on the stack and it gets destroyed when it goes out of scope.

    Quote Originally Posted by asafb View Post
    and what does Q_UNUSED(this) mean ?
    You can use it to suppress warnings about unused function arguments.

  3. #3
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: add link that open web browser on unix

    Qt 4.2 (released yesterday) includes QDesktopServices. This allows you to open URLs in a desktop-neutral manner. Give it an URL and it hands it off to the desktop to open, using the user's application preference.

    For example, an application of mine uses it for a website in the About Box. It opens in Firefox under Windows, Konqueror under KDE, and Safari under Mac, because those are my preferences.

  4. #4
    Join Date
    Jan 2009
    Posts
    6
    Thanks
    1

    Default Re: add link that open web browser on unix

    And nothing under gnome...or not for me anyways...

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: add link that open web browser on unix

    Quote Originally Posted by bwindorski View Post
    And nothing under gnome...or not for me anyways...
    Does your link have a proper scheme (eg. http)? What happens if you issue command "xdg-open http://www.qtcentre.org" in terminal?
    J-P Nurmi

  6. #6
    Join Date
    Jan 2009
    Posts
    6
    Thanks
    1

    Default Re: add link that open web browser on unix

    Yeah that opened a browser thanks. I've had little to no luck with the QUrl or QDesktopServices.

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: add link that open web browser on unix

    Quote Originally Posted by bwindorski View Post
    Yeah that opened a browser thanks. I've had little to no luck with the QUrl or QDesktopServices.
    Well then the problem must be with the URL because that's what QDesktopServices does behind the scenes. Make sure the link contains the scheme as I mentioned.
    J-P Nurmi

  8. #8
    Join Date
    Jan 2009
    Posts
    6
    Thanks
    1

    Default Re: add link that open web browser on unix

    Qt Code:
    1. QDesktopServices::openUrl ( QUrl ( "http://www.google.com" ) );
    To copy to clipboard, switch view to plain text mode 

    Its something with my GCofig

    this is the dbug-output

    GConf Error: Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash. See http://www.gnome.org/projects/gconf/ for information. (Details - 1: Failed to get connection to session: '=' character not found or has no value following it)

    not sure what it is looking into it.

    sorry asafb I'm not trying to hijack your post.

Similar Threads

  1. LINK : fatal error LNK1181: can't open 'delayimp.lib'
    By fcamlar in forum Installation and Deployment
    Replies: 10
    Last Post: 7th July 2006, 14:04
  2. Text Browser Link Question
    By taylor34 in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2006, 20:54
  3. Opening swf file in the default browser
    By munna in forum Qt Programming
    Replies: 16
    Last Post: 5th May 2006, 10:33
  4. open a browser
    By npc in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 11:23

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.