简体   繁体   中英

Qt Creator code as a user but run and debug as root

Would it be possible to execute QtCreator as a nornal user but run and debug an application as root?

That would be useful ie while developing applications based on WiringPi , which facilitates the access to GPIO but requires root to effectively enable access to the hardware.

To be more clear in my intentions, I would like that when I hit Ctrl+R in QtCretor, then it runs the app as root. And the same idea for debugging, when I hit F5 it starts debugging mode as root. All that while QtCreator is running by a normal user.

WiringPi does not need root access. You need to set properties to the relevant device nodes properly, that's all. Make sure you have /dev/gpiomem available for use by WiringPi, writable by the user. It's available on 4.1 and newer kernels IIRC.

Your question is a case of an XY problem. Yes, root access sidesteps the problem of wrong device node properties, but it's not a proper solution at all. Don't run your application as root.

The short answer is no. Even if you could start the application to run as root from within a non-root QtCreator context, you would not be able to connect to the running process and debug it.

You are better off just running QtCreator as root.

If you need to develop a "user mode" interface to the GPIO pins, you can try this tutorial: LED Driver

It shows a way to create nodes within the /sys tree that can give you usermode access to the GPIO.

I solved today the same issue with wiringPi following this comment: https://askubuntu.com/a/711130

In my case it was:

Tools-> Options-> Environment replaced the default string with "/usr/bin/xterm -e sudo" in terminal option.

Also, do not forget to go to Projects > Build & Run > Run and check the box Run in terminal .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM