PDA

View Full Version : [solved] Register new type in qml file from C++...



obiwankennedy
5th February 2016, 11:31
Hello,

I wrote an item: LineEdit.qml, and I have another qml 'main.qml) which creates many LineEdit items.
It works fine if I put LineEdit.qml into a directory with qmldir file etc..
But, that causes the need to carry several files, and this is not really friendly user. I would like to make all in one file.
main.qml is loaded into C++/Qt application.

So, I'm looking for solution about providing the LineEdit.qml from c++ into the qml context/engine/view.
So the first try is to save the LineEdit.qml into my application resource file, and load it into QQmlComponent, but I got the error: LineEdit is not a type.

Is there a way to do so ? I know that it possible to define my LineEdit through c++ class (subclassing QQuickItem or QQuickPaintedItem...) but it is easier for me if I keep the LineEdit.qml file approach as I don't have to get bored with painting code...


Thanks

anda_skoa
5th February 2016, 11:50
Just put it into the resource and "import" that resource path.
If you have main.qml in the resource as well, just use the relative path.

Cheers,
_

obiwankennedy
5th February 2016, 16:34
Yes, thanks, Actually I found this solution just after asking here.