PDA

View Full Version : component->loadUrl throws error



ChriD
31st January 2016, 15:42
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.



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!

anda_skoa
31st January 2016, 17:07
Well, what do the errors say?
Can you load the file in qmlscene?

Cheers,
_

ChriD
1st February 2016, 10:26
I tried it to load in a loader and all samples below work!



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:


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

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?

anda_skoa
1st February 2016, 10:37
I tried it to load in a loader and all samples below work!

Good to know.
The URIs looked fine already,



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,
_

ChriD
1st February 2016, 13:02
Well,

It was a similar nasty mistake :-)

The viewController is the parent object of the view class and i used the wrong cast


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!