<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QProcess not working in QT Creator (using qt version 6.3.0)]]></title><description><![CDATA[<p dir="auto">Hi.</p>
<p dir="auto">I am trying to run a simple QProcess task in a simple application written on QT Creator.</p>
<p dir="auto">The code is as follows:</p>
<pre><code>void Structure::on_button1_clicked()
{
    p = new QProcess(this);
    p-&gt;start("dir C:/Users");
    p-&gt;waitForFinished();
    QString output = p-&gt;readAllStandardOutput();
    qDebug&lt;&lt;output;
}
</code></pre>
<p dir="auto">However, the output I get is an empty string, even though the <code>Users</code> directory has a number of files and folders.<br />
I don't know what could be going wrong in such a simple process.</p>
<p dir="auto">I have already included the QProcess header.</p>
]]></description><link>https://forum.qt.io/topic/137109/qprocess-not-working-in-qt-creator-using-qt-version-6-3-0</link><generator>RSS for Node</generator><lastBuildDate>Sat, 12 Sep 2026 16:58:02 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/137109.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Jun 2022 10:31:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QProcess not working in QT Creator (using qt version 6.3.0) on Fri, 10 Jun 2022 07:18:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bigben">@<bdi>BigBen</bdi></a> said in <a href="/post/717074">QProcess not working in QT Creator (using qt version 6.3.0)</a>:</p>
<blockquote>
<p dir="auto">However, <code>p-&gt;startCommand("dir C:\\Users")</code> gives me no error and no output.</p>
</blockquote>
<p dir="auto">Well that is interesting.  As I said I only just discovered looking at the docs.  It's new in Qt 6.0.  I do not use Qt 6, nor Windows, so I cannot comment.  If you look at he examples at <a href="https://doc.qt.io/qt-6/qprocess.html#startCommand" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qprocess.html#startCommand</a> you can see them claiming to issue <code>dir</code> commands that way, that's all I can say.</p>
<blockquote>
<p dir="auto">I want to ask that in <code>p-&gt;start("cmd", { "/c", "dir C:\\Users" });</code>, what does the <code>/c</code> mean in the second argument?</p>
</blockquote>
<p dir="auto">The Windows/DOS <code>cmd.exe</code> takes various arguments, as you can see from running <code>cmd /?</code>.  Including:</p>
<pre><code>/C      Carries out the command specified by string and then terminates
</code></pre>
<p dir="auto">Basically without the <code>/c</code> it runs an interactive <strong>Command Prompt</strong>, the command-line console.  With the <code>/c</code> it interprets and executes the command line string following it, i.e. your <code>dir ...</code>.  It does not open a Command Prompt window and it returns to your code immediately after executing the command.  <code>dir</code> is built into <code>cmd.exe</code> --- along with many other "simple" commands like <code>echo</code> or <code>mkdir</code> --- there is no external <code>dir.exe</code> file to execute, so we need <code>cmd /c dir</code> to perform it.</p>
]]></description><link>https://forum.qt.io/post/717087</link><guid isPermaLink="true">https://forum.qt.io/post/717087</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 10 Jun 2022 07:18:47 GMT</pubDate></item><item><title><![CDATA[Reply to QProcess not working in QT Creator (using qt version 6.3.0) on Fri, 10 Jun 2022 02:51:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Hi. Thank you for the explanation. The command <code>p-&gt;start("cmd", { "/c", "dir C:\\Users" });</code> gives me the expected output.</p>
<p dir="auto">However, <code>p-&gt;startCommand("dir C:\\Users")</code> gives me no error and no output.</p>
<p dir="auto">I want to ask that in  <code>p-&gt;start("cmd", { "/c", "dir C:\\Users" });</code>, what does the <code>/c</code> mean in the second argument?</p>
]]></description><link>https://forum.qt.io/post/717074</link><guid isPermaLink="true">https://forum.qt.io/post/717074</guid><dc:creator><![CDATA[BigBen]]></dc:creator><pubDate>Fri, 10 Jun 2022 02:51:48 GMT</pubDate></item><item><title><![CDATA[Reply to QProcess not working in QT Creator (using qt version 6.3.0) on Thu, 09 Jun 2022 11:04:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bigben">@<bdi>BigBen</bdi></a></p>
<ul>
<li>
<p dir="auto"><a href="https://doc.qt.io/qt-6/qprocess.html#start" target="_blank" rel="noopener noreferrer nofollow ugc">QProcess::start(const QString &amp;program, const QStringList &amp;arguments = {}, QIODeviceBase::OpenMode mode = ReadWrite)</a> does <em>not</em> accept a complete command line, only a single executable as its first argument.  Change over to the correct new overload.</p>
</li>
<li>
<p dir="auto"><code>QProcess::readAllStandardOutput()</code> is not going to read an <em>error</em> message.  You must call <code>QProcess::readAllStandardError()</code> too.  You also don't attach to signal <code>QProcess::errorOccurred()</code>.  I think what you have will be generating one of these, possibly the latter.</p>
</li>
<li>
<p dir="auto"><code>dir</code> is not an executable program under Windows.  It is built into <code>cmd.exe</code>, which you must run.  (Unless Qt handles this for you, I don't have Qt under Windows.)</p>
</li>
<li>
<p dir="auto"><code>dir C:/Users</code> is wrong/lucky if it works under Windows.  Use proper native <code>\</code>s for paths in <code>QProcess</code> commands, it does not know an argument is a path and will not translate <code>/</code>s to <code>\</code>s for you, unlike e.g. <code>QFile</code>.</p>
</li>
</ul>
<pre><code>p-&gt;start("cmd", { "/c", "dir C:\\Users" });
p-&gt;waitForFinished();
QString output = p-&gt;readAllStandardOutput();
QString error = p-&gt;readAllStandardError();
</code></pre>
<p dir="auto"><strong>UPDATE</strong><br />
At Qt 6.0 it seems they introduced <a href="https://doc.qt.io/qt-6/qprocess.html#startCommand" target="_blank" rel="noopener noreferrer nofollow ugc">void QProcess::startCommand(const QString &amp;command, QIODeviceBase::OpenMode mode = ReadWrite)</a>.  So this would probably also work:</p>
<pre><code>p-&gt;startCommand("dir C:\\Users")
</code></pre>
]]></description><link>https://forum.qt.io/post/716998</link><guid isPermaLink="true">https://forum.qt.io/post/716998</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 09 Jun 2022 11:04:14 GMT</pubDate></item></channel></rss>