PDA

View Full Version : How to shutdown system in qt?



vani.pv
1st September 2012, 13:15
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?

Zlatomir
1st September 2012, 14:21
Try system("shutdown -s"); //lowercase 's'

vani.pv
3rd September 2012, 05:03
Its not working.Is there an other way?

ChrisW67
3rd September 2012, 05:51
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 (http://unixhelp.ed.ac.uk/CGI/man-cgi?shutdown+8) implementation, like mine, does not have a "-s" option and requires a mandatory period. The Mac OS X shutdown (http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/shutdown.8.html) 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

vani.pv
5th September 2012, 11:20
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.)

Lesiok
5th September 2012, 11:22
superuser or root

ChrisW67
5th September 2012, 22:37
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.


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.