Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 16
Registered: ‎02-08-2011
My Device: BlackBerry Z10
My Carrier: Rogers

Using Custom QML Components from a Static/Shared Library

Hello,

 

I have created a Cascades Shared Library so I can reuse code for applications. I am successfully able to access the library's C++ source files in the application that has imported them. However, I cannot do the same with QML files. The Qt documentation did have some material on creating custom QML modules but I did not have any luck. I also tried a workaround by creating a C++ class (CustomLabel) inside the library. This class extends bb::cascades::CustomControl. I am able to import the class without any issues into my application and I also have the following line in my applicationui.cpp file:

 

qmlRegisterType<CustomLabel>("CustomLabel", 1, 0, "CustomLabel");

 

However, when I go into main.qml on the application side, it cannot find the library when I enter in the following: import CustomLabel 1.0. However, If I define CustomLabel on the application side instead of the shared library, it works fine. 

 

Any idea of why that is happening? Is there any way to have custom QML components defined in a shared/static library such that it can be reused in an application?

 

Thanks.

Developer
Posts: 26
Registered: ‎07-21-2013
My Device: BB Z10 LE, BB DAC, BB PlayBook
My Carrier: Vodafone NL

Re: Using Custom QML Components from a Static/Shared Library

[ Edited ]

I'm having the same issue.

 

(I'm trying the C++ extend Cutomcontrol way)


When I try to add the qmlRegisterType, I get this error:

c:/bbndk/target_10_1_0_4828/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:162: undefined reference to `MyLibraryNamespace::CustomLabel::staticMetaObject'

 

do you also have this error or a similar error?

---
http://www.heris.nl OR Check out my apps in appworld:
http://appworld.blackberry.com/webstore/vendor/22561/
Developer
Posts: 26
Registered: ‎07-21-2013
My Device: BB Z10 LE, BB DAC, BB PlayBook
My Carrier: Vodafone NL

Re: Using Custom QML Components from a Static/Shared Library

I got it working for me:
I put a sample up on: 

https://github.com/RikScheffer/BB10LibrarySample

 

---
http://www.heris.nl OR Check out my apps in appworld:
http://appworld.blackberry.com/webstore/vendor/22561/