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;


    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


    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;


    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

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.