<?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[Always returns 0]]></title><description><![CDATA[<p dir="auto">I'm trying this simple program for learning and protoing purposes.</p>
<p dir="auto">In this example <strong>result</strong> is always 0 regardless of what I type into the input field. What am I doing wrong here?</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/24104181-40ac-47f7-8069-15c9433d5ec8.png" alt="1f15fe13-c2bf-47f7-baab-d22bb3e19130-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/topic/126843/always-returns-0</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 06:29:07 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/126843.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 20 May 2021 18:58:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:12:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pothos">@<bdi>Pothos</bdi></a><br />
You are mixing two possibilities for running your command.</p>
<p dir="auto">If you want to use <code>wattForStarted</code>/<code>Finished()</code> you must run your command via <code>start()</code>.</p>
<p dir="auto">Here for simplicity you could use <code>QProcess::execute()</code>, in which case its <em>return result</em> is the exit code you are looking for.</p>
<p dir="auto">Please go look at the doc page for <code>QProcess::execute()</code> and read what it says.  That is where your problem is.</p>
]]></description><link>https://forum.qt.io/post/660770</link><guid isPermaLink="true">https://forum.qt.io/post/660770</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 20 May 2021 19:12:21 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Fri, 21 May 2021 09:35:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pothos">@<bdi>Pothos</bdi></a> said in <a href="/post/660839">Always returns 0</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> I'm going to try the start()-version next as I will be trying to run an rsync-command next using this Qt-app.</p>
</blockquote>
<p dir="auto">Yes, that will be an example of a "long-running" command.  You will presumably not want your UI to be frozen/blocked while it executes, which it would be if you were to use <code>execute()</code>.  You will indeed want to use <code>start()</code>, and the various signals, so that it runs <em>asynchronously</em>.</p>
]]></description><link>https://forum.qt.io/post/660845</link><guid isPermaLink="true">https://forum.qt.io/post/660845</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 21 May 2021 09:35:25 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Fri, 21 May 2021 08:28:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kent-dorfman">@<bdi>Kent-Dorfman</bdi></a> in this particular case I think blocking the event loop is acceptable because, as JonB said, the command was so quick to execute, which means the user won't notice any freeze-up.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> I'm going to try the <code>start()</code>-version next as I will be trying to run an <code>rsync</code>-command next using this Qt-app.</p>
]]></description><link>https://forum.qt.io/post/660839</link><guid isPermaLink="true">https://forum.qt.io/post/660839</guid><dc:creator><![CDATA[Pothos]]></dc:creator><pubDate>Fri, 21 May 2021 08:28:28 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:45:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pothos">@<bdi>Pothos</bdi></a><br />
<code>execute()</code> "worked" here because it was the quickest way to show you the return result you thought was wrong.</p>
<p dir="auto">Because this command is so quick to execute you "get away" without noticing that the UI is blocked while that slot runs.</p>
<p dir="auto">That is what <a class="plugin-mentions-user plugin-mentions-a" href="/user/kent-dorfman">@<bdi>Kent-Dorfman</bdi></a> is drawing to your attention.</p>
<p dir="auto">If you <em>really</em> want to it right: use <code>start()</code>, but do <em>not</em> use those <code>waitFor...()</code> methods.  Use the <code>QProcess</code> <em>signals</em> like <code>finished()</code> to get the result back.  Then do whatever you want to do with the result in your slot for <code>finished()</code>.  Connect the other signals too, like <code>errorOccurred</code>.  If you do all this you'll understand a lot about how Qt programming with signals &amp; slots works!</p>
]]></description><link>https://forum.qt.io/post/660779</link><guid isPermaLink="true">https://forum.qt.io/post/660779</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 20 May 2021 19:45:21 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:36:38 GMT]]></title><description><![CDATA[<p dir="auto">Do you want concurrency or do you want to block until the process is completed?</p>
]]></description><link>https://forum.qt.io/post/660775</link><guid isPermaLink="true">https://forum.qt.io/post/660775</guid><dc:creator><![CDATA[Kent-Dorfman]]></dc:creator><pubDate>Thu, 20 May 2021 19:36:38 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:28:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Okay so <code>QProcess::execute()</code> is a static method. I managed to get my program work simply with  <code>int result = QProcess::execute("/usr/bin/mountpoint", {"-q", path})</code>. Thank you for the help.</p>
<p dir="auto">I'm still wondering: Can one say that either  <code>execute()</code> or <code>start()</code> is better in this particular case or is it just a matter of preference?</p>
]]></description><link>https://forum.qt.io/post/660773</link><guid isPermaLink="true">https://forum.qt.io/post/660773</guid><dc:creator><![CDATA[Pothos]]></dc:creator><pubDate>Thu, 20 May 2021 19:28:09 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:11:10 GMT]]></title><description><![CDATA[<p dir="auto">QByteArray QProcess::readAllStandardOutput(). You convert QByteArray to what you expect.</p>
]]></description><link>https://forum.qt.io/post/660771</link><guid isPermaLink="true">https://forum.qt.io/post/660771</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 20 May 2021 19:11:10 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:12:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pothos">@<bdi>Pothos</bdi></a><br />
You are mixing two possibilities for running your command.</p>
<p dir="auto">If you want to use <code>wattForStarted</code>/<code>Finished()</code> you must run your command via <code>start()</code>.</p>
<p dir="auto">Here for simplicity you could use <code>QProcess::execute()</code>, in which case its <em>return result</em> is the exit code you are looking for.</p>
<p dir="auto">Please go look at the doc page for <code>QProcess::execute()</code> and read what it says.  That is where your problem is.</p>
]]></description><link>https://forum.qt.io/post/660770</link><guid isPermaLink="true">https://forum.qt.io/post/660770</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 20 May 2021 19:12:21 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:09:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Here is the code copied:</p>
<pre><code>void MainWindow::on_testButton_clicked()
{
    QString path = ui-&gt;testPlainTextEdit-&gt;toPlainText();
    QProcess *testProcess = new QProcess(this);

    testProcess-&gt;waitForStarted();

    testProcess-&gt;execute("/usr/bin/mountpoint", {"-q", path});
    testProcess-&gt;waitForFinished();
    int result = testProcess-&gt;exitCode();

    qDebug()&lt;&lt; result;
    if (result == 0) {
        ui-&gt;testLabel-&gt;setText("Mounted.");
    } else {
        ui-&gt;testLabel-&gt;setText("Not mounted.");
    }

    ui-&gt;testPlainTextEdit-&gt;clear();
    ui-&gt;testPlainTextEdit-&gt;setFocus();

    // Close process and delete pointer variable
    testProcess-&gt;close();
    delete testProcess;
}
</code></pre>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/joecfd">@<bdi>JoeCFD</bdi></a> how to use?</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> yes it was a typo. Still doesn't work though.</p>
]]></description><link>https://forum.qt.io/post/660769</link><guid isPermaLink="true">https://forum.qt.io/post/660769</guid><dc:creator><![CDATA[Pothos]]></dc:creator><pubDate>Thu, 20 May 2021 19:09:24 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:07:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> Good catch !</p>
<p dir="auto">I was checking for mountpoint because of the unusual path it's located in. It might be a typo from <a class="plugin-mentions-user plugin-mentions-a" href="/user/pothos">@<bdi>Pothos</bdi></a> though.</p>
]]></description><link>https://forum.qt.io/post/660768</link><guid isPermaLink="true">https://forum.qt.io/post/660768</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 20 May 2021 19:07:40 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:08:39 GMT]]></title><description><![CDATA[<p dir="auto">testProcess-&gt;readAllStandardOutput() to match the output of command line run</p>
]]></description><link>https://forum.qt.io/post/660767</link><guid isPermaLink="true">https://forum.qt.io/post/660767</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 20 May 2021 19:08:39 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:07:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pothos">@<bdi>Pothos</bdi></a><br />
Please paste code I can copy, not a picture.</p>
<p dir="auto"><code>QProcess::execute()</code> is <code>static</code>.  You're not getting the exit code you think you are into your code.</p>
<p dir="auto">BTW,  conceptually you don't want a <code>QProcess::waitForStarted()</code><em>before</em> you have given it a process to start.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
It's <a href="https://www.man7.org/linux/man-pages/man1/mountpoint.1.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.man7.org/linux/man-pages/man1/mountpoint.1.html</a>.  Its exit code should vary according to what path is passed to it, that's what the OP is getting at.</p>
]]></description><link>https://forum.qt.io/post/660766</link><guid isPermaLink="true">https://forum.qt.io/post/660766</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 20 May 2021 19:07:00 GMT</pubDate></item><item><title><![CDATA[Reply to Always returns 0 on Thu, 20 May 2021 19:01:46 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">What is mountpoint ?<br />
Does it return any error code ?</p>
]]></description><link>https://forum.qt.io/post/660765</link><guid isPermaLink="true">https://forum.qt.io/post/660765</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 20 May 2021 19:01:46 GMT</pubDate></item></channel></rss>