View Full Version : QDesktopServices::openUrl() slow

3rd April 2009, 07:47

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?


3rd April 2009, 08:59
Make your firefox start faster, it's its fault. You can probably preload it to memory during system startup somehow.

3rd April 2009, 10:31
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 :)

3rd April 2009, 13:37
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.

3rd April 2009, 13:54
and this happens everytime?

3rd April 2009, 14:03
yeah, every time I've tried.

3rd April 2009, 14:16
ok, here is a course of action you can follow:

close firefox everytime and see how long it takes to open
close every other program in your machine
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.

4th May 2009, 06:51
After upgrading Firefox I found openURL() works much faster, but occasionally fails and returns false. So now as a backup I use QWebView (http://doc.trolltech.com/4.5/qwebview.html) if it fails:

if(!QDesktopServices::openUrl(url)) {

1st July 2010, 23:04
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).

2nd July 2010, 05:36
thanks for the tip.

23rd January 2011, 17:30
Para evitar que la aplicación se congele... usa un hilo:
To prevent the application from freezing ... a thread can be used:

The thread:

#include <QUrl>
#include <QDesktopServices>
#include <QThread>
#include <QLabel>
#include <QHBoxLayout>
class MyThread : public QThread {
MyThread(QUrl, QWidget* = 0);
void closePopUp();
void run();
QUrl url;
QWidget* qW;

MyThread::MyThread(QUrl u, QWidget* w ){
url = u;
qW = w;
void MyThread::closePopUp(){
if( qW ){
qW = 0;
void MyThread::run() {

The functions:

QWidget* createPopUp(QUrl url){
QWidget* qW = new QWidget();
QLabel* qLabel = new QLabel(qW);
qLabel->setText( url.toString() );
QLayout* qL = new QHBoxLayout(qW);
qW->setWindowFlags( Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::SubWindow
| Qt::WindowStaysOnTopHint );
qW->setWindowTitle("Opening url...");
qW->setFixedSize(qW->width(), qW->height() );
return qW;
MyThread* open_browser(const QString& rUrl, bool b = false ){
QUrl url = QUrl(rUrl, QUrl::TolerantMode);
MyThread* hilo;
if( b ){
hilo = new MyThread(url, createPopUp(url));
hilo = new MyThread(url);
return hilo;
The usage:

/*only open*/

/*open with popup but immediately it is closed*/
MyThread* hilo = open_browser("http://www.ewaewa.com/",true);

/*open with popup and close automatically when URL is opened*/