Results 1 to 11 of 11

Thread: QDesktopServices::openUrl() slow

  1. #1
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDesktopServices::openUrl() slow

    hello,

    I'm using QDesktopServices:: openUrl() to open a URL in the users default browser (in XP). The function does works and opens the URL in a Firefox tab, but only after 10-15 seconds and during that time my Qt app is frozen.

    If I call this function a second time then the delay is only ~3 seconds so it seems Qt takes time determining what is the default browser.

    Does anyone have experience with this or know how to open the web browser faster?

    thanks,
    Richard
    Last edited by rbp; 3rd April 2009 at 06:48. Reason: a smiley face was being inserted in my function call

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDesktopServices::openUrl() slow

    Make your firefox start faster, it's its fault. You can probably preload it to memory during system startup somehow.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices::openUrl() slow

    dont think at all its Qt's fault all Qt does on windows is call ShellExecute(..) with the url, after that its all windows job to find default browser,load it, show your url and puke..on my machine, its so fast, it makes my head spin

  4. #4
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices::openUrl() slow

    Make your firefox start faster, it's its fault.
    the thing is Firefox is already started in my test - Qt is just opening up a new tab. The first new tab takes a long time but subsequent tabs are quicker.

  5. #5
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices::openUrl() slow

    and this happens everytime?

  6. #6
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices::openUrl() slow

    yeah, every time I've tried.

  7. #7
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices::openUrl() slow

    ok, here is a course of action you can follow:

    1. close firefox everytime and see how long it takes to open
    2. close every other program in your machine
    3. u can also check memory consumption while browser is opening everytime


    you can also debug your app and check how long it takes for browser to open after shellExecute(...) function is executed. Also is there any thread running in your app? in either case, its a problem of machine/windows u have. i have used this api many times in many different tests without any complaints whatsoever.

  8. #8
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices::openUrl() slow

    After upgrading Firefox I found openURL() works much faster, but occasionally fails and returns false. So now as a backup I use QWebView if it fails:
    Qt Code:
    1. if(!QDesktopServices::openUrl(url)) {
    2. webview.load(url);
    3. webview.showMaximized();
    4. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Apr 2010
    Posts
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDesktopServices::openUrl() slow

    Hi rbp, I don't if you have already solve the problem of the slowness of opening the url, but in the team I'm working, we have found a solution. The problem (and I don't know why) is that while you're working inside the environment of Qt (QtCreator) it took the 30-40 sec to open the browser and show the url. But, if you run the .exe of your appllication (avoiding first the problem of loading the dlls, ie. mingwm10.dll, QtCore4.dll, QtGui4.dll, etc.) The url problem disappears. So my advice is to you keep working and when you realease your app, you would have no delay problems.

    Note: I have Windows Xp, QtCreator 2.0.0, Qt 4.7.0 (32 bits).

  10. #10
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices::openUrl() slow

    thanks for the tip.

  11. #11
    Join Date
    Jan 2011
    Posts
    1
    Platforms
    Unix/X11 Windows

    Lightbulb Re: QDesktopServices::openUrl() slow

    Para evitar que la aplicación se congele... usa un hilo:
    To prevent the application from freezing ... a thread can be used:

    The thread:
    Qt Code:
    1. #include <QUrl>
    2. #include <QDesktopServices>
    3. #include <QThread>
    4. #include <QLabel>
    5. #include <QHBoxLayout>
    6. class MyThread : public QThread {
    7. public:
    8. MyThread(QUrl, QWidget* = 0);
    9. void closePopUp();
    10. void run();
    11. private:
    12. QUrl url;
    13. QWidget* qW;
    14. };
    15.  
    16. MyThread::MyThread(QUrl u, QWidget* w ){
    17. url = u;
    18. qW = w;
    19. }
    20. void MyThread::closePopUp(){
    21. if( qW ){
    22. qW->~QWidget();
    23. qW = 0;
    24. }
    25. }
    26. void MyThread::run() {
    27. QDesktopServices::openUrl(url);
    28. closePopUp();
    29. terminate();
    30. wait();
    31. }
    To copy to clipboard, switch view to plain text mode 
    The functions:
    Qt Code:
    1. QWidget* createPopUp(QUrl url){
    2. QWidget* qW = new QWidget();
    3. QLabel* qLabel = new QLabel(qW);
    4. qLabel->setText( url.toString() );
    5. QLayout* qL = new QHBoxLayout(qW);
    6. qL->addWidget(qLabel);
    7. qW->setLayout(qL);
    8. qW->setWindowFlags( Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::SubWindow
    9. | Qt::WindowStaysOnTopHint );
    10. qW->setWindowTitle("Opening url...");
    11. qW->show();
    12. qW->setFixedSize(qW->width(), qW->height() );
    13. return qW;
    14. }
    15. MyThread* open_browser(const QString& rUrl, bool b = false ){
    16. QUrl url = QUrl(rUrl, QUrl::TolerantMode);
    17. MyThread* hilo;
    18. if( b ){
    19. hilo = new MyThread(url, createPopUp(url));
    20. }else{
    21. hilo = new MyThread(url);
    22. }
    23. hilo->start();
    24. return hilo;
    25. }
    To copy to clipboard, switch view to plain text mode 
    The usage:
    Qt Code:
    1. /*only open*/
    2. open_browser("http://www.ewaewa.com/");
    3.  
    4. /*open with popup but immediately it is closed*/
    5. MyThread* hilo = open_browser("http://www.ewaewa.com/",true);
    6. hilo->closePopUp();
    7.  
    8. /*open with popup and close automatically when URL is opened*/
    9. open_browser("http://www.ewaewa.com/",true);
    To copy to clipboard, switch view to plain text mode 
    Last edited by enwillyado; 23rd January 2011 at 16:38.

Similar Threads

  1. Why is drawText so terribly slow?
    By Ntoskrnl in forum Qt Programming
    Replies: 8
    Last Post: 1st August 2008, 19:15
  2. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  3. Designer form creation very slow
    By MrGarbage in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 22:20
  4. Slow painting in QGraphicsView
    By JonathanForQT4 in forum Qt Programming
    Replies: 12
    Last Post: 16th July 2007, 09: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.