How to lauch an external file from Qt?

c++, external, file, qt

Solution

You can use Qt native methods to achieve this behaviour by calling

QDesktopServices::openUrl(QUrl::fromLocalFile("someFilePath"));

See QUrl::fromLocalFile() and QDesktopServices::openUrl()

(Refer to this post)

Problem

I'd like to open a pdf file simply double-clicking on one element of a QListWidget. I created a batch file to open Acrobat Reader (reader.bat), but I want a specific pdf file: ``` void MainWindow::on_FileListWidget_itemDoubleClicked(QListWidgetItem *item) { QFile SelectedModel(Current_Path + "/Template/" + item->text()); QString FileName; FileName = (Current_Path + "/Template/" + item->text()); ::system("e:\\reader.bat"); } ``` 1) I don't know what's could be better from QFile or QString in order to identify and choose the file from the QListWidget; 2) I dont' know how to add the file to the command to open Acorbat Reader (in the shown line I'm able to open the program but not my file). Any idea?

Original source