Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a file with Qt when there is no default program for it?

Tags:

c++

qt

There is a QDesktopServices::openUrl function in Qt which opens files with default programs, like when you want to open .docx file with Microsoft Office. However, the function will simply return 0 and do nothing if there is no default program assotiated with the file extension of the requested file. I would like Qt to show something like this instead:

enter image description here

A cross-platform solution would be ideal.

Is it possible with Qt?

like image 895
Oleg Yablokov Avatar asked Dec 22 '25 01:12

Oleg Yablokov


1 Answers

This one works for me. But I didn't test it anywhere except my Windows 7 machine

QDesktopServices::openUrl(QUrl::fromLocalFile("D:/file"));
like image 173
Mykhailo Bryzhak Avatar answered Dec 23 '25 16:12

Mykhailo Bryzhak