我正在写一个QT应用程序,它有一个关机按钮。我想用此按钮关闭系统,但是当我使用shell命令“shutdown -h now”时,系统要求输入密码。
我想关闭没有密码。系统在ubuntu中无密码关机11.04
我的QT代码:
QObject *parent;
myProcess = new QProcess(this);
QString command= "sudo shutdown";
QStringList arguments;
arguments << "-h " << "now" ;
myProcess->start(command,arguments);
你有没有想过权限?要么你让程序setuid(坏主意),make'/ sbin/shutdown' setuid(坏主意),要么将当前用户添加到'/ etc/sudoers'文件,以便你可以从你的'sudo/sbin/shutdown'运行程序(麻烦)。 – trojanfoe 2012-04-10 11:24:45