<?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[Using signals and slots in a static method?]]></title><description><![CDATA[<p dir="auto">I am making a static method that can be used across our code base. It is intended to be able to restart a motion controller, ping the motion controllers address, and once a response is recieved, return "true"</p>
<p dir="auto">However, since it's a static class, I can't get the connection to work.</p>
<pre><code>bool GmasManager::gmasSoftReset()
{
    bool gmasRestarted = false;
    QProcess p;
    QStringList args;
    args &lt;&lt; "-t" &lt;&lt; GmasIP;
    QObject::connect(&amp;p, &amp;QProcess::readyReadStandardOutput, [=]
    {
        QString s = p.readAllStandardOutput();
        qDebug() &lt;&lt; s;
        if(s.contains("bytes"))
        {
            p.close();
            gmasRestarted = true;
        }
    });
    p.start("ping", args);
    return gmasRestarted;
}
</code></pre>
<p dir="auto">However I'm getting a list of errors with this code:</p>
<pre><code>error: C2248: 'QProcess::QProcess' : cannot access private member declared in class 'QProcess'
</code></pre>
<pre><code>error: C2662: 'QByteArray QProcess::readAllStandardOutput(void)' : cannot convert 'this' pointer from 'const QProcess' to 'QProcess &amp;'
Conversion loses qualifiers
</code></pre>
<pre><code>error: C2662: 'void QProcess::close(void)' : cannot convert 'this' pointer from 'const QProcess' to 'QProcess &amp;'
Conversion loses qualifiers
</code></pre>
<pre><code>error: C3491: 'gmasRestarted': a by-value capture cannot be modified in a non-mutable lambda
</code></pre>
<p dir="auto">I'm completely baffled. I have used this sort of logic in other places in the code without issue. I need some way to read from the standard out to determine when the motor controller restarts, but I can't seam to do that in a static method.</p>
]]></description><link>https://forum.qt.io/topic/90445/using-signals-and-slots-in-a-static-method</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 11:23:41 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/90445.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 04 May 2018 14:29:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Using signals and slots in a static method? on Fri, 04 May 2018 20:02:40 GMT]]></title><description><![CDATA[<p dir="auto">The way you wrote it won't do what you expect. Your <code>p</code> object will get destroyed at the end of <code>gmasSoftReset </code>.</p>
]]></description><link>https://forum.qt.io/post/456420</link><guid isPermaLink="true">https://forum.qt.io/post/456420</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 04 May 2018 20:02:40 GMT</pubDate></item><item><title><![CDATA[Reply to Using signals and slots in a static method? on Fri, 04 May 2018 14:52:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> Actually, my process will carry on forever because of how I set ping up. I just want to kill the process as soon as I receive bytes back from the ping. It's not a fixed amount of time. Various factors affect the restart time of the controllers from machine to machine, so I want to set a very long process time out, and just wait to hear when bytes are received.</p>
<p dir="auto">I have not yet added that functionality because I'm just trying to get the signal working at this point.</p>
]]></description><link>https://forum.qt.io/post/456395</link><guid isPermaLink="true">https://forum.qt.io/post/456395</guid><dc:creator><![CDATA[graniteDev]]></dc:creator><pubDate>Fri, 04 May 2018 14:52:27 GMT</pubDate></item><item><title><![CDATA[Reply to Using signals and slots in a static method? on Fri, 04 May 2018 14:49:37 GMT]]></title><description><![CDATA[<p dir="auto">He passes the context by value. QProcess is a QObject, therefore it can't be copied. Hence the error his getting.</p>
]]></description><link>https://forum.qt.io/post/456394</link><guid isPermaLink="true">https://forum.qt.io/post/456394</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 04 May 2018 14:49:37 GMT</pubDate></item><item><title><![CDATA[Reply to Using signals and slots in a static method? on Fri, 04 May 2018 14:40:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Yes, but these are compilation errors!?</p>
]]></description><link>https://forum.qt.io/post/456391</link><guid isPermaLink="true">https://forum.qt.io/post/456391</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 04 May 2018 14:40:35 GMT</pubDate></item><item><title><![CDATA[Reply to Using signals and slots in a static method? on Fri, 04 May 2018 14:35:49 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">From the looks of it, you should rather use <a href="http://doc.qt.io/qt-5/qprocess.html#waitForFinished" target="_blank" rel="noopener noreferrer nofollow ugc">QProcess::waitForFinished</a>.</p>
<p dir="auto">Because currently, you are going to return from your function probably before the lambda has been called.</p>
]]></description><link>https://forum.qt.io/post/456388</link><guid isPermaLink="true">https://forum.qt.io/post/456388</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 04 May 2018 14:35:49 GMT</pubDate></item></channel></rss>