Getting environment variables in QML
-
I saw help documentation https://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html
I hope to get environment variables (QML_PUPPET_MODE)in qml

But I have no way
Whether it can only get the environment variable on the c++ https://forum.qt.io/topic/80788/calling-environment-variables -
I saw help documentation https://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html
I hope to get environment variables (QML_PUPPET_MODE)in qml

But I have no way
Whether it can only get the environment variable on the c++ https://forum.qt.io/topic/80788/calling-environment-variables@Martin-Wells
In your
main.cppfile you can grab the env vars usingQProcessEnvironmentand add them as a context property...app.getEngine().rootContext()->setContextProperty("env", QProcessEnvironment::systemEnvironment().toStringList());This is pretty raw and they will still need parsing so maybe you'd want to do that and then pass in a
QVariantMapinstead.In your
main.qmlyou can try this by printingenvin, say,Component.onCompleted -
This post is deleted!
-
I saw help documentation https://doc.qt.io/qtcreator/creator-qml-modules-with-plugins.html
I hope to get environment variables (QML_PUPPET_MODE)in qml

But I have no way
Whether it can only get the environment variable on the c++ https://forum.qt.io/topic/80788/calling-environment-variables@Martin-Wells said in Getting environment variables in QML:
But I have no way
Whether it can only get the environment variable on the c++Yes you can get this environment variable from C++
qgetenv("QML_PUPPET_MODE").
Then you can add it in the current QML context:
app.getEngine().rootContext()->setContextProperty("QML_PUPPET_MODE", qgetenv("QML_PUPPET_MODE")) -
@Martin-Wells
In your
main.cppfile you can grab the env vars usingQProcessEnvironmentand add them as a context property...app.getEngine().rootContext()->setContextProperty("env", QProcessEnvironment::systemEnvironment().toStringList());This is pretty raw and they will still need parsing so maybe you'd want to do that and then pass in a
QVariantMapinstead.In your
main.qmlyou can try this by printingenvin, say,Component.onCompleted@kindid
Thank you this is a good idea.