[Interest] SingletonType functions not visible in QML

mark diener rpzrpzrpz at gmail.com
Sat May 23 12:11:19 CEST 2015


How would somebody "install" the singleton to work in qmlscene (quick 2)?

Or someway to simulate the singleton functions in QML?

This way the QML preview functionality would be available

Here is the QML Scene Output:

#######

Starting external tool "/macdev/qt541/5.4/clang_64/bin/qmlscene"
/macdev/qdev/testsingleton/main.qml

file:///macdev/qdev/testsingleton/main.qml:6 module "Singapi" is not
installed



"/macdev/qt541/5.4/clang_64/bin/qmlscene" finished
#########

But no preview is shown!

I am thinking that I have a separate qmlproject that has a fake Singapi QML
file that provides all the functions of the singleton
but does not do anything really useful.

Maybe even a Singleton QML?


On Fri, May 22, 2015 at 8:01 AM, Dmitry Volosnykh <
dmitry.volosnykh at gmail.com> wrote:

> Example is fine.
>
> On Fri, May 22, 2015 at 6:00 PM, rpzrpzrpz at gmail.com <rpzrpzrpz at gmail.com>
> wrote:
>
>> Hello:
>>
>> So do we need a static Sing* in the singleton provider or is the example
>> in the documentation correct?
>>
>> I would guess the provider is called ONCE by the QML engine and not
>> multiple times, but I am usually mistaken.
>>
>> But I guess the static allocation will remove all doubt?
>>
>> Ben Lau -> Thank you
>> Dmitry Volosnykh -> Thank you
>>
>> Mark
>>
>>
>> On 5/22/2015 8:35 AM, Samuel Stirtzel wrote:
>> > 2015-05-22 16:30 GMT+02:00 Dmitry Volosnykh <dmitry.volosnykh at gmail.com
>> >:
>> >> Samuel, what you ask is explained here:
>> >> http://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterSingletonType-2
>> >>
>> >> citation:
>> >>
>> >> NOTE: A QObject singleton type instance returned from a singleton type
>> >> provider is owned by the QML engine. For this reason, the singleton
>> type
>> >> provider function should not be implemented as a singleton factory.
>> >>
>> >
>> > Ah ok thanks, at the first glance this code looked quite malicious,
>> > but reading the documentation sure helps ;)
>> >
>> >> On Fri, May 22, 2015 at 5:27 PM, Samuel Stirtzel <
>> s.stirtzel at googlemail.com>
>> >> wrote:
>> >>>
>> >>> 2015-05-22 15:56 GMT+02:00 mark diener <rpzrpzrpz at gmail.com>:
>> >>>
>> >>>> static QObject *singprovider(QQmlEngine *gengine, QJSEngine
>> >>>> *gscriptEngine)
>> >>>> {
>> >>>>      Q_UNUSED(gengine)
>> >>>>      Q_UNUSED(gscriptEngine)
>> >>>>      Sing* gsing = new Sing();
>> >>>>      return gsing;
>> >>>> }
>> >>>
>> >>> Is the return value of the function cached in qt internally?
>> >>> Or will this just create a new "singleton" with every call?
>> >>>
>> >>> how about this:
>> >>>
>> >>> static Sing* gsing = new Sing();
>> >>>
>> >
>> >
>>
>> --
>> No spell checkers were harmed during the creation of this message.
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150523/1b7d6b44/attachment.html>


More information about the Interest mailing list