Results 1 to 11 of 11

Thread: QDesktopServices::openUrl() slow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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).

  2. #2
    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.

  3. #3
    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
  •  
Qt is a trademark of The Qt Company.