In ubuntu,how to use qt to compile and debug a programme needing environment variables



  • My English is not so good.At first, I use cmake and terminal to compile a programme needing environment variables. In this way, I always enter a command "source ......sh" to set my environment variables. Now, I need to use qt to debug my programme. However, I don't know how to set environment variables in qt. I'll appreciate your help, thank you!



  • The environment variables for any program are inherited from the shell that starts the app. Since Qt creator is starting the app, you will inherit environment variables that Qt inherited. So, you would want to open a shell, set your environment variables, then start QtCreator from that shell. Then, when you run your app from QtCreator, the environment variables you need should be there.

    The other option would be to add some code to your main.cpp to set the environment variables while you are testing, or add some other method to your code to fake the correct environment variables.

    Hope this helps!

    P.S. Your English is actually pretty good!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    If you are using Qt Creator, you can go on the Run part of the Project panel. There you can add/remove/modify environment variables as needed for testing your application.



  • @fbaqt thanks, I do it through run qt in terminal.


  • Moderators

    @yicong-liu Then set needed variables in the same terminal before starting your application


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.