Create built-in quick component in C++
-
I need to create QQuickText in C++. I use this code:
@
QQmlType *type = QQmlMetaType::qmlType("QtQuick/Text", 2, 0);
if (type)
{
QObject *obj = type->create();
QQuickItem item = qobject_cast<QQuickItem>(obj);
qDebug() << item;
}
@It work, but I had to include <private/qqmlmetatype_p.h>. There is another way?
-
See "this":http://qt-project.org/doc/qt-4.8/qtbinding.html#loading-qml-components-from-c guide (it's for QtQuick 1, but it works the same in QML2, you just need to change class names).