How can I open a file by associated, external program and if it fails call a "open with..." dialog?
Can it be platform independent code? Or I need to use
constructions to implement "open with..." dialog call for every platform?
Thanks in advance
EDIT: Update, after few hours of researching, i found good solution for Windows.
We try to open file with ShellExecute(...), if it fails with file association error, we open file by "open as" Shell32.dll dialog
QString file_path = "C:\VeryGoodPath.txt";
int iResult = (int)ShellExecuteA(0, 0, file_path.toStdString().c_str(), 0, 0 , SW_SHOW );
// Succesful run
QString ShellCmd = "C:\\Windows\\system32\\shell32.dll,OpenAs_RunDLL \""+file_path +"\"";
ShellExecuteA(0,"open", "C:\\Windows\\system32\\rundll32.exe",ShellCmd.toStdString().c_str(),NULL, SW_NORMAL);
EDIT2: Problem was, that i dont use in
One easy way is to use
This way you can let the operating system handle it. If a program is associated with that file (or URL in general. You can use this function to open an url in the default browser, too) the operating system will launch it or show the default "Open with" dialog.