问题
Would it be possible to execute QtCreator as a nornal user but run and debug an application as root?
That would be useful i.e. 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.
回答1:
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 X-Y 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.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/37599106/qt-creator-code-as-a-user-but-run-and-debug-as-root