<?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[How to continually run QProcess while running my QML program?]]></title><description><![CDATA[<p dir="auto">The problem I have in my code is, once the QML engine uplouded the QProcess stop!!</p>
<pre><code>#include &lt;QQmlContext&gt;
    #include &lt;QGuiApplication&gt;
    #include &lt;QQmlApplicationEngine&gt;
    #include &lt;usbdeviceid.h&gt;
    #include &lt;iostream&gt;
    #include &lt;QProcess&gt;
    using namespace std;

    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        bool scanForDevices=0;
        USBdeviceID *usbdeviceid =new USBdeviceID();
        engine.rootContext()-&gt;setContextProperty("USBdeviceID", usbdeviceid);
        QProcess OProcess;
        QString Command;    //Contains the command to be execute
        Command = "lsusb";
     
        while (1)
        {
            OProcess.start(Command,QIODevice::ReadOnly); //Starts execution of command
            OProcess.waitForFinished();   //Waits for execution to complete

            QString StdOut      =   OProcess.readAllStandardOutput();  
            QString StdError    =   OProcess.readAllStandardError();  

            cout&lt;&lt;"\n Printing the standard output..........\n";
            cout&lt;&lt;endl&lt;&lt;StdOut.toStdString();
            bool mouse1 = StdOut.contains("ID 046d:c03e");                                                   
            bool keyBoard1 = StdOut.contains("ID 413c:1003"); 

            if (mouse1 ==1 &amp;&amp; keyBoard1==1)
            {
                scanForDevices=1;
            }

            if (scanForDevices==1)
            {
                // start main program
                // revoke A signal to tell QML the correct devices are connected
                usbdeviceid-&gt;setMouse1Detected(1);
                usbdeviceid-&gt;setkeyBoard1Detected(1);
                engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
                if (engine.rootObjects().isEmpty())
                    return -1;
                return app.exec();
            }
        }
       }
      }


</code></pre>
]]></description><link>https://forum.qt.io/topic/106064/how-to-continually-run-qprocess-while-running-my-qml-program</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 01:55:31 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/106064.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Aug 2019 10:01:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to continually run QProcess while running my QML program? on Tue, 20 Aug 2019 14:30:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dheerendra">@<bdi>dheerendra</bdi></a> Can you explain more with code!</p>
]]></description><link>https://forum.qt.io/post/546999</link><guid isPermaLink="true">https://forum.qt.io/post/546999</guid><dc:creator><![CDATA[MAthias_Va 0]]></dc:creator><pubDate>Tue, 20 Aug 2019 14:30:55 GMT</pubDate></item><item><title><![CDATA[Reply to How to continually run QProcess while running my QML program? on Tue, 20 Aug 2019 12:31:28 GMT]]></title><description><![CDATA[<p dir="auto">You have multiple issues in your program. Why are you starting the infinite while loop in the main ? You are not loading the qml unless your process finishes as you are looking for waitForFinished.</p>
<p dir="auto">Best thing is start your process based on some event e.g. Use timer.</p>
<p dir="auto">Then things should work fine.</p>
]]></description><link>https://forum.qt.io/post/546987</link><guid isPermaLink="true">https://forum.qt.io/post/546987</guid><dc:creator><![CDATA[dheerendra]]></dc:creator><pubDate>Tue, 20 Aug 2019 12:31:28 GMT</pubDate></item></channel></rss>