[Interest] QQmlEngine, QQmlComponent, QQmlContext
mark diener
rpzrpzrpz at gmail.com
Tue Aug 18 00:27:40 CEST 2015
Hello List:
I am trying to execute 2 calls to QQmlComponent( ).setData() and
QQmlComponent.create() .
When I instantiate the first component, I want to make it visible to the
second QQmlComponent also instantiated with QQmlComponent.setData() and
then QQmlComponent.create( ).
So there must be some way of loading the first component, get the context
built correctly so when
the second component is built, it can find the "Myrect" component from the
first and display it correctly instead of triggering messages "Myrect is
not a type"
I am missing something between QQmlComponent, QQmlContext, and
QQmlApplicaitionEngine.
Any of the qml guys on 5.4.2 or above set me in the right direction?
Thank you,
md
#####Code sample below##########
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QUrl>
#include <QDebug>
#include <QQmlComponent>
#include <QQmlContext>
int main(int argc, char *argv[])
{
QGuiApplication gapp(argc, argv);
QQmlApplicationEngine geng;
qDebug() << "Import paths:" << geng.importPathList() << endl ;
qDebug() << "Base URL:" << geng.baseUrl() << endl ;
//Early test code (discard for later)
//geng.load(QUrl(QStringLiteral("qrc:/main.qml")));
QByteArray gbc ;
gbc.clear() ;
gbc.append("import QtQuick 2.4\n Rectangle { color: \"red\"; x:
40; y: 40; height: 40; width: 40 }") ;
//QQmlContext* gct = geng.rootContext() ;
QString gsurl = geng.baseUrl().toString() ;
gsurl += "Myrect" ;
QUrl gurl(gsurl) ;
qDebug() << "Myrect path:" << gurl << endl ;
QQmlComponent gcomp(&geng) ;
gcomp.setData(gbc,gurl) ;
gcomp.create() ;
if (gcomp.isError() == true)
{
qDebug() << "Base Component not created:" << gcomp.errors() << endl ;
return 0 ;
}
//gct->setContextProperty("Myrect",gocomp);
QByteArray gbs ;
gbs.clear() ;
gbs.append("import QtQuick 2.4\n import QtQuick.Window 2.2\n
Window { color: \"purple\"; visible: true; visibility:
Qt.WindowFullScreen\n Myrect { id: grect } }") ;
QQmlComponent gscreen(&geng) ;
gscreen.setData(gbs,QUrl()) ;
//QObject* gwin = gcomp.create() ;
//gscreen.create() ;
if (gscreen.isError() == true)
{
qDebug() << "Screen errors:" << gscreen.errors() << endl ;
return (0) ;
}
return gapp.exec();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150817/0509f2cf/attachment.html>
More information about the Interest
mailing list