component->loadUrl throws error
I want to create a QML Comonent on runtime.
I found some samples and i tried it, but i am not always getting an abortion when laoding the URL into the component.
I tried several URLs to be sure i got a working one but i always get the abortion (read acces Violation) which i thought is a Problem when getting the qml file.
Code:
QQmlComponent *component = new QQmlComponent(viewController.getAppEngine().data());
//component->loadUrl(QUrl("qrc:///qml/components/LabelStringEdit.qml")); // ABORTION IS HERE!!! This line should work in my opinion...
//component->loadUrl(QUrl("qrc:/qml/components/LabelStringEdit.qml"));// ABORTION IS HERE!!!
//component->loadUrl(QUrl("qrc:module/settings/view_settings_connector_sageX3.qml"));// ABORTION IS HERE!!!
component
->loadUrl
(QUrl::fromLocalFile("C:/Development/QtTest/qml/components/LabelStringEdit.qml"));
// ABORTION IS HERE!!! QQuickItem *quickItem = qobject_cast<QQuickItem*>(component->create());
QQuickItem *parentQuickItem = qobject_cast<QQuickItem*>(_rootObject);
QQmlEngine::setObjectOwnership(quickItem, QQmlEngine::CppOwnership);
quickItem->setParent(this);
quickItem->setVisible(true);
quickItem->setParentItem(parentQuickItem);
Is there anything i am doeing wrong?
The QML is a Quck QML file...
Thanks!
Re: component->loadUrl throws error
Well, what do the errors say?
Can you load the file in qmlscene?
Cheers,
_
Re: component->loadUrl throws error
I tried it to load in a loader and all samples below work!
Code:
Loader {
width: 500;
height: 500;
source: "qrc:///qml/components/LabelStringEdit.qml";
}
Loader {
width: 500;
height: 500;
source: "qrc:/qml/components/LabelStringEdit.qml";
}
The error i get:
Quote:
Debug Error
File: global\qglobal.cpp
Line: 2966
ASSERT: "e" in file ...qqmlengine_p.h line 378
With the QMLSCENE it does not work because i do have an Import in my LabelStringEdit.qml
Code:
import "qrc:/qml/components" as Controls
ans of course qmlscene cant find "qrc:/qml/components" but my app should find?! Do i have to provide the Import path to the "QQmlComponent" class?
Re: component->loadUrl throws error
Quote:
Originally Posted by
ChriD
I tried it to load in a loader and all samples below work!
Good to know.
The URIs looked fine already,
Quote:
Originally Posted by
ChriD
The error i get:
I was more thinking along the lines of the errors reported by QQmlComponent::errors(), but you are hitting an assert.
Are you sure that viewController.getAppEngine().data() is a valid QQmlEngine pointer?
Cheers,
_
Re: component->loadUrl throws error
Well,
It was a similar nasty mistake :-)
The viewController is the parent object of the view class and i used the wrong cast
Code:
View::ViewController viewController = qobject_cast<View::ViewController>(this->parent()); // of course wrong because parent() returns a pointer
View::ViewController *viewController = qobject_cast<View::ViewController*>(this->parent()); // this is correct...
In fact there was no Compiler error and the Controller and the engine object was filled, but pointed anywhere in the memory
It works now!
Thank You!