LKBEN11641: How to find windows command line variables to use in a qt c++ application?
Symptom
You need to resolve some environment variable from windows to use in your c++ application.
Cause
This is by design.
Solution
Sometimes you need to know the path to an environment variable like %programdata% to use in your Qt application. To resolve these variables in code, you can use different methods. One of the is via the getenv() function.
Here an example to resolve $env:ProgramData from the powershell or %programdata% from the cmd:
QString script = getenv("Programdata");
As an alternative you can use the qEnvironmentVariable() fucntion or make use of the QStandardPaths::standardLocations() function.
Have fun.
Disclaimer:
The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!About the Author
Author:
- Keskon GmbH & Co. KGWim Peeters is electronics engineer with an additional master in IT and over 30 years of experience, including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform.
Latest update: 24.01.2023