3

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.

jww
  • 97,681
  • 90
  • 411
  • 885
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • Of course you can develop and debug your application as a normal user. Why wouldn't you be able to? Of course you can execute your final application as the root user - why wouldn't you be able to? "root" can run any executable he/she wants to. You can use `sudo` to run a single command with root privileges (assuming it's configured corrrectly) or just use `su` to switch to a root shell and then run your app. You can of course also just configure your IDE to use `sudo` when running your app. – Jesper Juhl Jun 02 '16 at 18:16
  • Possible duplicate of [running the code as root on Qt-Creator SDK](https://stackoverflow.com/questions/16136035/running-the-code-as-root-on-qt-creator-sdk) – Alexandr Zarubkin Aug 02 '19 at 13:20

3 Answers3

4

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.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • I'll appreciate a lengthily version of this answer, considering an environment based on Debian Jessie as is the case for Raspbian. – KcFnMi Jun 02 '16 at 23:30
1

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.

Community
  • 1
  • 1
iGian
  • 11,023
  • 3
  • 21
  • 36
  • This is a good idea until your app accidentally deletes something crucial to your system's normal operation... – rubenvb Jun 24 '16 at 21:07
  • Of course, but in my case I do not mind! Also KcFnMi maybe does not mind, since the question was "Would it be possible to execute QtCreator as a nornal user but run and debug an application as root?" – iGian Jun 25 '16 at 04:38
0

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.

J Carl Zeigler
  • 138
  • 1
  • 6