I need to know how to get the user name and/or home directory of the users. I've googled around for a while but can only find the variables for C++ or BASH.
How do I get the user name or home directory? I'm writing in QML.
I need to know how to get the user name and/or home directory of the users. I've googled around for a while but can only find the variables for C++ or BASH.
How do I get the user name or home directory? I'm writing in QML.
My solution was like this:
1.) create
config.h
file with theConfig
class:2.) set the
setContextProperty(...)
in yourmain.cpp
Then you can simply call
config.getHome()
in your qml-js file.This is how I implemented it:
QmlEnvironmentVariable.h
QmlEnvironmentVariable.cpp
Then in
main()
add a call to qmlRegisterSingletonType (or in your re-implemented QQmlExtensionPlugin::registerTypes() method if you're creating a plugin):Finally, use it in QML like so:
You would have to get the Username in C++ and then exchange that data from C++ to qml.
Read here how to exchange data between qml and C++.