[Qt-qml] Accessing C++ singleton from QML

Alex alexlordax+qt at gmail.com
Wed Oct 27 21:04:02 CEST 2010


Hi all,

This is probably a silly question, but how do I access a singleton
instance of a C++ class from QML?

For example, I have:

class Settings : QObject {
public:
  static Settings *instance();

private:
  Settings();
};

In my QML code, I want to do the moral equivalent of the following:

property variant mySettings : Settings::instance()


What is the recommended way of doing this?

Thanks,
Alex


PS:  On a related note, I am using "variant" above because I can't
even qmlRegisterType the Settings class, since it doesn't have a
public default constructor.



More information about the Qt-qml mailing list