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

Alex alexlordax+qt at gmail.com
Thu Oct 28 20:32:58 CEST 2010


On Wed, Oct 27, 2010 at 7:20 PM,  <bea.lam at nokia.com> wrote:
> On 28/10/2010, at 5:04 AM, ext Alex wrote:
>>
>> In my QML code, I want to do the moral equivalent of the following:
>>
>> property variant mySettings : Settings::instance()
>>
>
> The static function can't be directly called from QML.
>
> One way to do it would be to return Settings::instance() from a property instead:
>
> class MyAppData : public QObject
> {
>        Q_OBJECT
>        Q_PROPERTY(Settings* settings READ settings)
>
> public:
>        Settings *settings() const { return Settings::instance(); }
> };


Yup, I got this far...


>
> For the Settings class, if you register it using the version of qmlRegisterType() that takes no arguments, it does not need a default constructor.
>
>

... and this is the part I was missing.  Thanks!

Alex




More information about the Qt-qml mailing list