c++ class that adds a drawable qquickitem
-
..not a good title, I'm sorry..
I'm reading a lot in these days, but couldn't find what I need, but I think it is simpler that I imagine.I need dynamically created objects, but those objects are both a c++ class and a drawable item.
From instructions taken HERE I can dynamically create qml objects. and it works.
Next I understand that to be able to create the class in runtime, when I need, the right way is to use
qmlRegisterType<MyClass>("myClass", 1, 0, "MyClass");... and it works too..
I've read that to have the possibility of draw objects, I have to derive my c++ class from QQuickItem, instead of QObject, but I didn't find any example, nor how to implement this.
Can you help me?
Let's say that I have a button. every time I click that I want to add a c++ object class to a QList and draw a Rectangle with information inside. After that object variables are changed in main.cpp, and visualization should change accordingly. -
..not a good title, I'm sorry..
I'm reading a lot in these days, but couldn't find what I need, but I think it is simpler that I imagine.I need dynamically created objects, but those objects are both a c++ class and a drawable item.
From instructions taken HERE I can dynamically create qml objects. and it works.
Next I understand that to be able to create the class in runtime, when I need, the right way is to use
qmlRegisterType<MyClass>("myClass", 1, 0, "MyClass");... and it works too..
I've read that to have the possibility of draw objects, I have to derive my c++ class from QQuickItem, instead of QObject, but I didn't find any example, nor how to implement this.
Can you help me?
Let's say that I have a button. every time I click that I want to add a c++ object class to a QList and draw a Rectangle with information inside. After that object variables are changed in main.cpp, and visualization should change accordingly.@spiderdab said in c++ class that adds a drawable qquickitem:
Let's say that I have a button. every time I click that I want to add a c++ object class to a QList and draw a Rectangle with information inside. After that object variables are changed in main.cpp, and visualization should change accordingly.
Why do you need a C++ QQuickItem for that?
All that can be done with a c++ model and a view (ListView, Repeater, ...) with delegates in QML.I would also recommend not to use
Qt.createQmlObjectorQt.createComponentfrom your link (too imperative) and stay on the declarative side by using models and views. -
@spiderdab said in c++ class that adds a drawable qquickitem:
Let's say that I have a button. every time I click that I want to add a c++ object class to a QList and draw a Rectangle with information inside. After that object variables are changed in main.cpp, and visualization should change accordingly.
Why do you need a C++ QQuickItem for that?
All that can be done with a c++ model and a view (ListView, Repeater, ...) with delegates in QML.I would also recommend not to use
Qt.createQmlObjectorQt.createComponentfrom your link (too imperative) and stay on the declarative side by using models and views. -
Yes it can, follow your second link if you want that.