How to get a system's default browser?

813 views Asked by At

Is there a Qt interface to get the system's default browser?

I want to open a file:// url explicitly in a browser instead of the system's default application, so QDesktopServices::openUrl is not the way because of

If the URL is a reference to a local file (i.e., the URL scheme is "file") then it will be opened with a suitable application instead of a Web browser.

1

There are 1 answers

0
Kuba hasn't forgotten Monica On

For your particular application, you should use the web engine that comes with Qt:

QWebEngineView *view = new QWebEngineView{parent};
view->load(QUrl{"file://...."});
view->setWindowFlags(Qt::Window);
view->setAttribute(Qt::WA_DeleteOnClose);
view->show();

If the html is simple enough, use the text browser:

QTextBrowser *view = new QTextBrowser{parent};
view->setSource(Qurl{"file://...."});
view->setWindowFlags(Qt::Window);
view->setAttribute(Qt::WA_DeleteOnClose);
view->show();