PDA

View Full Version : How to shutdown Linux machine from QT Program?



Kevin Hoang
20th August 2010, 09:04
I try to use QProcess:execute("/sbin/poweroff") but nothing happen. Some body help me a way to do?

antialias
20th August 2010, 10:36
I'm not on a Linux machine at the moment but what happens if you try:

QStringList arguments << "-h" << "now";
QProcess:execute("shutdown", arguments)

(if you don't post for the next 3 minutes I'll assume it worked :p )

Kevin Hoang
20th August 2010, 12:41
Thank for your helping!

The problem is the shutdown command require root for shutting down, but my program run as user account.

barnabyr
20th August 2010, 20:42
You need to chown it to root and set the SUID bit on your application. That way when another user runs your program it wil run as root instead of them. As this is a potential security hole make sure only root has write permission.