How can i set the build in properties right?
I create a QQuickItem via QQmlComponent:
LoadQuickItem::LoadQuickItem(QQmlEngine* engine, QQuickItem* parentView, QObject *parent) : QObject(parent) {
this->engine_ = engine;
this->parentView_ = parentView;
this->component_ = new QQmlComponent(engine, QUrl("qrc:///Item.qml"));
this->obj_ = new QObject();
this->continueLoading();
}
LoadQuickItem::~LoadQuickItem() {
delete this->component_;
delete this->obj_;
delete this->item_;
}
void LoadQuickItem::continueLoading() {
if (this->component_->isError()) {
qWarning() << this->component_->errors();
} else {
qDebug() << "Create QQuickItem";
this->obj_ = this->component_->create();
QQmlEngine::setObjectOwnership(this->obj_, QQmlEngine::CppOwnership);
this->item_ = qobject_cast<QQuickItem*>(this->obj_);
this->item_->setParentItem(this->parentView_);
this
}
}
Instance:
QQuickWindow wnd;
QQmlEngine engine;
LoadQuickItem* item1 = new LoadQuickItem(&engine, wnd.contentItem());
qDebug() << (item1->getItem()->setProperty("id", "item1") ? "Succes" : "Failed: item1->getItem()->setProperty(\"id\", \"item1\")");
Item.qml
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
Button {
text:"Maximize"
tooltip:"Press me"
style: CustomStyle {}
}
I want to set the property “id”, but always get a false.
The property ought to be known?
Background, I would like load files via a QML and use them as templates. A QML file always contains only one control, eg a button.
Any idear?
↧