Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to use QProcess for restarting the device



  • Hi,

    Unlike a pc type, my device works continuesly (7/24). Somehow the user must re-start the device.
    My shotdown look like this;

    system("poweroff");
    

    Poweroff works nicely. And yesterday I use QProcess for the ping command as;

       // Create QProcess object
        proc = new QProcess();
        proc->start("ping", QStringList() << "-c" << "3" << QString(m_sHostName));
    

    For the restart first I try to use;

    system("shutdown -r 0");
    

    and nothing happened. So I decided to use QProcess for start as;

            // Create QProcess object
            procR = new QProcess();
            procR->start("shutdown" << "-r" << "0");
    

    then I get a compile error as;

    /home/ntms/Desktop/ELITCARD/mainwindow.cpp:374: error: invalid operands of types 'const char [9]' and 'const char [3]' to binary 'operator<<'
    

    Any help please,

    Kind Regards


  • Lifetime Qt Champion

    Hi,

    Look again at your ping start line to build the parameters.



  • @SGaist Thank you again.

    I forget the "reboot". My device usr/sbin had a rebboot app so simply I call as;

    system("reboot");
    

    And its works nicely. For shutdown, poweroff and the reboot doesn't need any parameters.

    Kind Regards,


  • Lifetime Qt Champion

    You can also use QProcess and not pass any arguments



  • @NTCYP said:

            // Create QProcess object
            procR = new QProcess();
            procR->start("shutdown" << "-r" << "0");
    

    Just saw that you had a C++ syntax problem. You try to stream char arrays into a char array. That is not healthy and the reason why the compiler complains.



  • @SGaist Yes both worked. It seems much faster to use system("reboot"). Device is not accessible from network. So I don't have any security concern to use "system". Thank you for your insight, appreciated.

    Kind Regards,


Log in to reply