nyarlathotep108
nyarlathotep108

Reputation: 5531

Qt Creator Run Environment Ignored

I am building a console application in Linux Ubuntu. Setting environment variables in Qt Creator's Run Environment panel is not working, both if I switch on the flag "Run in terminal" or not. It looks like they are just ignored. If I export those variables outside Qt Creator, in a plain terminal, and then run my console application, everything is fine.

I am using Qt Creator 3.5.1.

Upvotes: 0

Views: 1012

Answers (1)

MrJman006
MrJman006

Reputation: 770

Ok so I think you are setting the variables in the correct place, but just in case here is a screen shot of where I set mine.One thing to note which we already discussed in the comments is what "kit" you are running. In the screenshot below, I only have one kit set up, but if you have more than one, you have to choose the appropriate kit by clicking on the little monitor icon in the bottom left of Qt Creator.

enter image description here

Then in code I use the following:

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    // Get the variable or a default value if the variable is not set.
    // Qt abstraction that should work cross platform.
    QString s = QProcessEnvironment::systemEnvironment().value("VAR_ONE", "");

    // Get variable in platform dependent way.
    char * s2 = getenv("VAR_ONE");

    // Print out the results.
    qDebug("%s", s.toStdString().c_str());
    qDebug("%s", s2);


    return a.exec();
}

If you are doing all of this and still having issues, I would try making an new empty console application and see if the above works to narrow down if the problem is with your Qt Creator in some way or if the project you are working in has some setting that is off.

Upvotes: 1

Related Questions