[Qt-qml] Qml Object static function

985 views
Skip to first unread message

Jesus Fernandez

unread,
Dec 5, 2011, 12:39:56 PM12/5/11
to qt-...@qt.nokia.com
Hi,

Is there a way to have a Qml object with a function that doesn't require the object instantiation?
I want to create a Qml object with a show function to create Object dynamicly. The function behaviour will be like a object factory (Static class function)

Best regards.

Artem Marchenko

unread,
Dec 5, 2011, 4:32:44 PM12/5/11
to Jesus Fernandez, qt-...@qt.nokia.com
Hi Jesus

I don't think there is a natural way to do so as QML is supposed to be declarative primarily.

You can, however, achieve the nearly same results by putting your factory functions to JavaScript of either a parent QML object or JavaScript library.

Cheers,
Artem.

> _______________________________________________
> Qt-qml mailing list
> Qt-...@qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml

_______________________________________________
Qt-qml mailing list
Qt-...@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

bea...@nokia.com

unread,
Dec 6, 2011, 6:55:40 PM12/6/11
to jsf...@gmail.com, qt-...@qt.nokia.com


If you don't want a custom QML type to be instantiable, you can register it using the overloaded version of qmlRegisterType() that doesn't take any arguments

See the discussion at http://lists.qt.nokia.com/pipermail/qt-qml/2010-October/001470.html


cheers,

Bea

Bo Thorsen

unread,
Dec 7, 2011, 4:27:01 AM12/7/11
to qt-...@qt.nokia.com
Den 07-12-2011 00:55, bea...@nokia.com skrev:
>
> On 06/12/2011, at 3:39 AM, ext Jesus Fernandez wrote:
>
>> Hi,
>>
>> Is there a way to have a Qml object with a function that doesn't require the object instantiation?
>> I want to create a Qml object with a show function to create Object dynamicly. The function behaviour will be like a object factory (Static class function)

You should take a look at the Loader element.

http://doc.qt.nokia.com/latest/qml-loader.html

You can also do this with a javascript function that uses Component.

> If you don't want a custom QML type to be instantiable, you can register it using the overloaded version of qmlRegisterType() that doesn't take any arguments
>
> See the discussion at http://lists.qt.nokia.com/pipermail/qt-qml/2010-October/001470.html

If this is what he wants, I'd go with registering a global object on the
context instead of this weird hack.

Bo Thorsen,
Fionia Software.

--

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk

Reply all
Reply to author
Forward
0 new messages