PDA

View Full Version : QProcess to shutdown doesn't work



davethomaspilot
28th January 2024, 01:35
I have this method:


void MainWindow::shutdown()
{
//::gpioWrite(ENA_12V,PI_LOW);
QProcess process;
qDebug() << "Powering down the rpi" ;
process.startDetached("sudo systemctl poweroff --no-block");
}

It's running on an RPI (Bookworm 64 bit OS). The pi doesn't shutdown.

If I run


sudo systemctl poweroff --no-block

the rpi shuts down as expected.

Why doesn't it work as a QProcess?

Ginsengelf
29th January 2024, 07:27
Hi, does it work when you start your Qt program with sudo, and then only call systemctl without the sudo?
Does it work if you use /sbin/poweroff?
And lastly: does it work if you use system() instead of QProcess?

Ginsengelf

davethomaspilot
31st January 2024, 22:11
Hi, ?
Does it work if you use /sbin/poweroff?
And lastly: does it work if you use system() instead of QProcess?

Ginsengelf

Thanks for the suggestions!


does it work when you start your Qt program with sudo, and then only call systemctl without the sudo
The application is already being run under sudo. I removed the sudo from the command executed, but still doesn't work.



Does it work if you use /sbin/poweroff?

Yes!

Apparently the --noblock is not recognized.

I got that from code I used back on Stretch. Without the --noblock, it sometimes took minutes before the rpi shut down.

Thank you!