Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
C++ and QML Integration
Currently i am building a game using Qt Quick and i am using QQuickView and QQuickItem to create instances of my objects from QML files, for example i have a game character "image in qml file" and i am loading it using QComponent and QQuickItem and then i add it to the parent "QQuickView", now i want this character to respond to my keyboard events.
Hi @AhmedYossef and Welcome to Qt Devnet.
Thanks for the reply, i did that i sub classed QQuickItem, and in the constructor of the character i created the QQMLComponent and the QQuickItem, then i add the QQuickItem to the parent which is the QQuickView, then i set focus and i set initial X and Y for the character, also i implemented the keyPressEvent, but still nothing happens the character appears in the default X and Y i set before but when i press the key it doesn't go to the event
@AhmedYossef Can you post some code ? Did you set focus ?
Here is what i do in the constructor of the character
QQmlComponent component(view->engine(), QUrl(QStringLiteral("qrc:/PlayerTank.qml")));
tankItem = qobject_cast<QQuickItem*>(component.create());
tankItem->setX(100); tankItem->setY(100); tankItem->setFocus(true);
tabkItem is a QQuickItem
Got it to work finally, i implemented the Keypressevents for the class that subsclassed the QQuickView and it works i can now move the characters