Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom basic type in QML?

I don't seem to find any resources on adding basic types to QML. I don't mean QObject or higher derived elements, but the basic types - bool, int, real and so on.

Didn't have any luck digging for it in the sources as well...

So any info is appreciated.

like image 653
dtech Avatar asked Jul 13 '26 19:07

dtech


1 Answers

I assume you want to register more complex types than int, bool, real, since they are already present.

You cannot do this in Qt 4.x. It is possible in Qt 5 (QML 2), but there is no public API. If you still want to do it, you'll need to dig into some code to see how its done, as there's no documentation.

You need to implement a QQmlValueTypeProvider (qqmlglobal_p.h) and create QQmlValueTypeBase<> subclasses (qqmlvaluetype_p.h) for each of your types. Then register your value type provider with QQml_addValueTypeProvider() in your plugin's registerTypes().

One example you could look at are QGeoCoordinate, QGeoRectangle, etc. from QtLocation module: http://qt.gitorious.org/qt/qtlocation/trees/master/src/imports/location

Good luck.

like image 76
MartinJ Avatar answered Jul 17 '26 17:07

MartinJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!