0

I set environment variable this way:

export MY_DIR="$HOME/projects"

Then I want to read that variable in my program:

char *name = getenv("MY_DIR");

but I get a null value, Edit 1: when I run the program using Qt Creator.

When I compile:

g++ myprogram.cpp -o myprogram

and run:

./myprogram

the program form a terminal I get correct variable.

Irbis
  • 11,537
  • 6
  • 39
  • 68

1 Answers1

0

At the left tab you can click at 'Projects', which will show you some options. At the "Build & Run' tab, click the 'Run' button below, then search for "Run Environment". Open it's details and there you can add or edit variables that will be available while your program is running.

enter image description here

Salsa
  • 917
  • 2
  • 13
  • 22