Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QProcess doesn't work with "reboot" command
Forum Updated to NodeBB v4.3 + New Features

QProcess doesn't work with "reboot" command

Scheduled Pinned Locked Moved Solved Mobile and Embedded
10 Posts 5 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kate_Software
    wrote on last edited by
    #1

    Hi,

    I am trying to reboot my Linux system using QProcess.start() method. QProcess.start() works with all commands I have tried except from "reboot"... This is how my code looks like:

    QProcess myprocess;
    myprocess.start("reboot");

    Any line after these two is not being executed but the system doesn't reboot either.

    Any help?

    Thanks.

    jsulmJ JonBJ KroMignonK 3 Replies Last reply
    0
    • K Kate_Software

      Hi,

      I am trying to reboot my Linux system using QProcess.start() method. QProcess.start() works with all commands I have tried except from "reboot"... This is how my code looks like:

      QProcess myprocess;
      myprocess.start("reboot");

      Any line after these two is not being executed but the system doesn't reboot either.

      Any help?

      Thanks.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @Kate_Software What happens if you execute "reboot" manually in a shell? Do you need sudo or root rights to be able to reboot?
      On my Ubuntu system reboot is in /sbin which means sudo is needed to execute it.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      5
      • jsulmJ jsulm

        @Kate_Software What happens if you execute "reboot" manually in a shell? Do you need sudo or root rights to be able to reboot?
        On my Ubuntu system reboot is in /sbin which means sudo is needed to execute it.

        K Offline
        K Offline
        Kate_Software
        wrote on last edited by
        #3

        Hi @jsulm, from the command window everything works well. I don't need super user... (I have tried with both with sudo, and without anyway just in case it makes any difference but it doesn't).
        This is in Ubuntu xenial 32 bits...

        ODБOïO 1 Reply Last reply
        0
        • K Kate_Software

          Hi @jsulm, from the command window everything works well. I don't need super user... (I have tried with both with sudo, and without anyway just in case it makes any difference but it doesn't).
          This is in Ubuntu xenial 32 bits...

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #4

          @Kate_Software hi,
          maybe reading the output of the process can give a hint

          QString output = QString::fromLocal8Bit(process->readAllStandardOutput());
          
          1 Reply Last reply
          3
          • K Kate_Software

            Hi,

            I am trying to reboot my Linux system using QProcess.start() method. QProcess.start() works with all commands I have tried except from "reboot"... This is how my code looks like:

            QProcess myprocess;
            myprocess.start("reboot");

            Any line after these two is not being executed but the system doesn't reboot either.

            Any help?

            Thanks.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Kate_Software
            As @LeLev says you should always check the output from a QProcess. However, you need to read both stdout & stderr. Additionally, you should also slot onto https://doc.qt.io/qt-5/qprocess.html#errorOccurred (which may well be what is happening to you here).

            However, you have a problem if you are sure when you say:

            Any line after these two is not being executed

            It's hard to believe that is the case, are you truly sure about this? You might also hook onto https://doc.qt.io/qt-5/qprocess.html#started.

            EDIT What is the scope of your QProcess myprocess;? Although I would have thought a process once started would continue to run even if it goes out of scope, it might be that destructing it kills off the sub-process, I don't know....

            1 Reply Last reply
            3
            • K Kate_Software

              Hi,

              I am trying to reboot my Linux system using QProcess.start() method. QProcess.start() works with all commands I have tried except from "reboot"... This is how my code looks like:

              QProcess myprocess;
              myprocess.start("reboot");

              Any line after these two is not being executed but the system doesn't reboot either.

              Any help?

              Thanks.

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by
              #6

              @Kate_Software said in QProcess doesn't work with "reboot" command:

              Any line after these two is not being executed but the system doesn't reboot either.

              Is your application running as root?
              Or do you have give the right to run reboot? (eg. with sudo?)

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              JonBJ 1 Reply Last reply
              0
              • KroMignonK KroMignon

                @Kate_Software said in QProcess doesn't work with "reboot" command:

                Any line after these two is not being executed but the system doesn't reboot either.

                Is your application running as root?
                Or do you have give the right to run reboot? (eg. with sudo?)

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @KroMignon
                Just an observation: while what you have written is quite possibly the root of the OP's problem, it would not explain her "Any line after these two is not being executed"....

                KroMignonK 1 Reply Last reply
                0
                • JonBJ JonB

                  @KroMignon
                  Just an observation: while what you have written is quite possibly the root of the OP's problem, it would not explain her "Any line after these two is not being executed"....

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by KroMignon
                  #8

                  @Kate_Software said in QProcess doesn't work with "reboot" command:

                  Any line after these two is not being executed"

                  Can you show the code extract to see how you are calling "reboot"?
                  I do something similar with a linux embedded device and QProcess::execute("reboot"); do the job for me.

                  In my case, the application is running as root.
                  If don't want this, you can use sudo ==> QProcess::execute("sudo", QStringList() <<"/sbin/reboot");
                  After according the rights to use reboot to your user with visudo -f /etc/sudoers.d/myApp

                  # Allow user appUser to run reboot as root without password
                  appUser ALL = (root) NOPASSWD: /sbin/reboot
                  
                  

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply
                  0
                  • JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    I think @KroMignon's last post was aimed at @Kate_Software, not at me.

                    Note that you can take this approach if & only if your application is intended only for your own use on your own machine. If you are intending to distribute your program, you cannot do things this way.

                    KroMignonK 1 Reply Last reply
                    0
                    • JonBJ JonB

                      I think @KroMignon's last post was aimed at @Kate_Software, not at me.

                      Note that you can take this approach if & only if your application is intended only for your own use on your own machine. If you are intending to distribute your program, you cannot do things this way.

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by
                      #10

                      @JonB Oh sorry, reply was to fast! And yes, this solution is not relevant for distributed application... but there are not very much application which are not embedded/dedicated for a specific HW which requires to reboot the machine.

                      So I supposed this is for a very custom/specific use case, not to be distribute with apt or any other packaging system.

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved