Results 1 to 7 of 7

Thread: How to shutdown system in qt?

  1. #1
    Join Date
    Aug 2012
    Posts
    33
    Qt products
    Qt3
    Platforms
    Unix/X11

    Unhappy How to shutdown system in qt?

    Hi to all.

    In my application i need to check for the password to activate my application.If the password entered is wrong then i need to shut down my system.
    I use
    System("shutdown -s");
    but its not working.
    Is there any other command or function to do it?

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to shutdown system in qt?

    Try system("shutdown -s"); //lowercase 's'

  3. #3
    Join Date
    Aug 2012
    Posts
    33
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to shutdown system in qt?

    Its not working.Is there an other way?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to shutdown system in qt?

    Quote Originally Posted by vani.pv View Post
    System("shutdown -s");
    but its not working.
    "its not working" is not a useful description of the problem. Since you've left us guessing, I guess that one or several of these apply:
    • your user does not have superuser privileges;
    • shutdown is not in the application's path;
    • your shutdown implementation, like mine, does not have a "-s" option and requires a mandatory period. The Mac OS X shutdown does have a "-s" option, but your profile indicates you are using Linux/UNIX.

    You should investigate sudo if you need controlled escalation to root privileges.
    Is there any other command or function to do it?
    Yes plenty, but they all require the same superuser privileges as shutdown:
    • /sbin/init 0
    • /sbin/telinit 0
    • /sbin/shutdown -h now
    • /sbin/halt
    • /sbin/poweroff

  5. #5
    Join Date
    Aug 2012
    Posts
    33
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to shutdown system in qt?

    what is superuser privilege?

    my application path is:
    vani/jwork/p2pacu2012/antennacontrolunit.pro.

    so how could i set this path to shutdown my system?

    sbin/init 0
    /sbin/telinit 0
    /sbin/shutdown -h now
    /sbin/halt
    /sbin/poweroff

    I dint get ehat all these except they are part of sbin directory.Iam using linux(redhat.)

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to shutdown system in qt?

    superuser or root

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to shutdown system in qt?

    Quote Originally Posted by vani.pv View Post
    what is superuser privilege?
    Users on Linux systems fall into two groups: the system super user (root), and everyone else. Commands that affect the whole system typically require the user to be running as root. Other users are not permitted to execute commands of this nature. Any command you find in /sbin or /usr/sbin requires super user privilege to perform its function completely, although some offer partial function to ordinary users (e.g. /sbin/ifconfig).

    my application path is:
    vani/jwork/p2pacu2012/antennacontrolunit.pro.
    I do not know what you want us to do with this piece of information.

    so how could i set this path to shutdown my system?

    sbin/init 0
    /sbin/telinit 0
    /sbin/shutdown -h now
    /sbin/halt
    /sbin/poweroff

    I dint get ehat all these except they are part of sbin directory.Iam using linux(redhat.)
    You asked for other commands that can shut the system down: that is what this list is. You need to execute one of the commands above, with the correct arguments, and with a suitable set of user privileges to shut down your system.

    You can use QProcess::execute() to execute the command: this is the only part of this that has anything to do with Qt.

    Quote Originally Posted by Me
    You should investigate sudo if you need controlled escalation to root privileges.
    sudo is a controlled way to allow non-root users to execute very limited root-only commands.

Similar Threads

  1. How to set a signal before shutdown?
    By inger in forum Newbie
    Replies: 12
    Last Post: 4th June 2012, 07:30
  2. shutdown the system with progress bar
    By baobui in forum Newbie
    Replies: 1
    Last Post: 17th May 2011, 08:01
  3. Shutdown on Mac failing
    By ntp in forum Qt Programming
    Replies: 4
    Last Post: 11th December 2010, 01:41
  4. Replies: 1
    Last Post: 15th August 2010, 11:13
  5. Finalization on system shutdown
    By nomadoro in forum Qt Programming
    Replies: 4
    Last Post: 30th October 2009, 19:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.