PDA

View Full Version : how to get root privilege for QProcess to run installer on Mac



fong
15th April 2015, 08:00
Hi

I have a gui app on mac os x which want to do a auto update on start, what i want to do:
1).download the new mpkg file;
2).use QProcess to run "installer -pkg MY_APP.mpkg -target LocalSystem" to install the newly downloaded mpkg file;

my code:


QProcess* proc = new QProcess();
QString cmd = "installer -pkg MY_APP.mpkg -target LocalSystem";
proc->start(cmd);
if (!proc->waitForFinished())
qDebug() << "install failed:" << proc->errorString();
else
qDebug() << "install output:" << proc->readAll();
delete proc;
the result is: install output: "installer: Must be run as root to install this package."
so i changed the code to like this:

QString cmd = "sudo installer -pkg MY_APP.mpkg -target LocalSystem";
But it didn't work and output nothing.

What i want is: when proc->start,it will pop up a system gui to let user input passwork,just like double-clicked a mpkg to start a install process.

I've searched through google and in this forum,but didn't get this solved.
Can anyone help?
Thanks in advance.

stampede
15th April 2015, 08:08
(...) just like double-clicked a mpkg
I've never tried that on mac, but maybe this will work:


QDesktopServices::openUrl(QUrl::fromLocalFile("MY_APP.mpkg"));

quote from QDesktopServices docs:


If the URL is a reference to a local file (i.e., the URL scheme is "file") then it will be opened with a suitable application instead of a Web browser.

fong
15th April 2015, 08:32
I've never tried that on mac, but maybe this will work:


QDesktopServices::openUrl(QUrl::fromLocalFile("MY_APP.mpkg"));

quote from QDesktopServices docs:
It works and it's exactly what I want.Thank you!