How to deal with dynamically created QQuickItem’s

Today I’d like to share some knowledge in form of small Qt C++/QML mixed project

The project is about chess game. Since its created for demonstration purposes, there is no battle mode, no AI and pieces moves checking missing some features such as en-passant etc

Code located here: ChessQML

Actually, inter-operate between C++ code and QML code in Qt framework pretty easy, however, there is few tips’n’tricks. For example: Make sure your objects’s pointer, created at C++ side and then passed to QML have to register its ownership to QML engine as C++ ownership:

QQmlEngine::setObjectOwnership(obj_ptr, QQmlEngine::CppOwnership);

This makes sense only for QObject’s derived classes

Please, leave your comments

 

Leave a Reply