Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to launch the associated application for a file / directory / URL?
    primarykey
    data
    text
    <p><strong>Linux</strong> seems to be easy: <code>xdg-open &lt;file/directory/URL&gt;</code>. </p> <p>Apparently, <strong>Mac</strong> is similar: <code>open</code> should be used instead of <code>xdg-open</code>. I don't have access to a Mac so I couldn't test it.</p> <p>For <strong>Windows</strong>, I found 4 different suggestions and those that I have tried failed.</p> <ul> <li><p><a href="https://stackoverflow.com/q/1480971/341970">Is there a non-java, cross platform way to launch the associated application for a certain file type?</a> suggests <br/><code>start</code></p></li> <li><p><a href="https://stackoverflow.com/q/2765823/341970">How to give focus to default program of shell-opened file, from Java?</a> suggests <br/> <code>cmd /c start ...</code></p></li> <li><p><a href="https://stackoverflow.com/q/526037/341970">How to open user system preferred editor for given file?</a><br> <a href="https://stackoverflow.com/q/2211209/341970">How to Find Out Default File Opener with Java?</a> suggest <br/> <code>RUNDLL32.exe</code></p></li> <li><p><a href="https://stackoverflow.com/q/11007537/341970">What is the correct way to use ShellExecute() in C to open a .txt</a><br> <a href="https://stackoverflow.com/q/5127249/341970">Open file with Windows&#39; native program within C++ code</a><br> <a href="https://stackoverflow.com/q/10737854/341970">How to use ShellExecute to open html files in Windows using C++?</a> suggest <br/> <code>ShellExecute</code></p></li> </ul> <p>I have tried the first 3 with <code>system()</code> and <code>QProcess::startDetached()</code> and <code>"http://www.stackoverflow.com"</code> as argument but they all failed; <code>start</code> works just fine from the command line though. I haven't tried <code>ShellExecute</code> yet.</p> <p><strong>What is the Windows equivalent of <code>xdg-open</code>?</strong> It seem to me, it is <code>start</code> but why did my attempts with <code>start</code> fail?</p> <p><strong>Is <code>ShellExecute</code> my only option?</strong></p> <hr> <p><strong>EDIT</strong> I thought <code>QDesktopServices::openUrl()</code> was for web pages only because it did not work for files or directories.</p> <p>After some debugging I figured out that if I replace <code>\\</code> with <code>/</code> in the path on Windows, it works for files but the directories are still not opened. Any ideas what I am doing wrong?</p> <pre><code>QDir dir("C:/Documents and Settings/ali"); qDebug() &lt;&lt; "Exists? " &lt;&lt; dir.exists(); qDebug() &lt;&lt; dir.absolutePath(); QDesktopServices::openUrl(QUrl(dir.absolutePath())); qDebug() &lt;&lt; "External app called"; </code></pre> <p>Application Output:</p> <pre class="lang-none prettyprint-override"><code>Exists? true "C:/Documents and Settings/ali" External app called </code></pre> <p>But nothing happens, the directory is not opened. On Linux, directories are opened with the default file manager as expected.</p> <hr> <p><strong>SOLUTION:</strong> Due to the Qt bug <em>and</em> Windows quirks (malformed application window), I ended up using <code>ShellExecute</code>. That gives me enough flexibility to achieve exactly what I want at some expense...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload