Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Environment variables inside the main fuction
Qt 6.12 LTS is out! See what's new in the release blog

Environment variables inside the main fuction

Scheduled Pinned Locked Moved Unsolved General and Desktop
environment var
2 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • veryqtpersonV Offline
    veryqtpersonV Offline
    veryqtperson
    wrote on last edited by
    #1

    I was watching this video: QtWS15- Effective QML, and speaker (Thomas) said that you cannot set environment variables inside the main function.

    But I have them there and they do work:

    int main(int argc, char *argv[])
    {
        // here's the environment variable
        qputenv("QSG_VISUALIZE", "overdraw");
    
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    
        return app.exec();
    }
    

    Has something changed for the last year? Or I don't understand something?

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, I think he's referring to when you have statically declared class instances, the constructors for them are run before your main() starts.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt
      • Unsolved