[SOLVED] Add a QTreeView in QML


I would like to register a QTreeView c++ object to QML.
I tried to register it like this:


qmlRegisterType<QTreeView>("com.MyApp.QTreeView", 1, 0, "QTreeView");

relevant code in main.qml

import com.MyApp.QTreeView 1.0

QWindow {
        headerHidden: true

Result: it compiles. headerHidden property is found so it is registered correctly. However I have an error at runtime:
ASSERT: "!d->isWidget" in file kernel\qobject.cpp, line 2090


QWidgets are not directly compatible with QML such that they can be embedded in a QML view. They are two different UI technologies and cannot be used together in that fashion.

You can however embed a QML view inside of a QWidget hierarchy:


Or just use the QML TreeView component instead:


Answered By – David K. Hess

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *