How to run print command lpr -p programmatically throgh root privilage in Qt

白昼怎懂夜的黑 提交于 2019-12-08 18:34:30

you can run commands that need root privilege by running :

echo myPass | sudo -S lpr -p

Although it's not a good idea to echo your password in shell but you can do it in Qt via Qprocess like :

QProcess process1;
QProcess process2;

process1.setStandardOutputProcess(&process2);

process1.start("echo myPass");
process2.start("sudo -S lpr -p");
process2.setProcessChannelMode(QProcess::ForwardedChannels);


process2.waitForFinished(3000);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!