I've just begun to learn Qml.Altought i read too many qt tutorial, still struggling with some problems. I want to make multipages desktop application using OpenGL. First of all, in main function of the program, i am transmitting class instance so that i could access them in qml by using below code snippet.
QQmlApplicationEngine engine;
Foo foo;
engine.rooContext()->setContextProperty(QStringLiteral("foo"),&foo);
But if i must instance all of classes that i want to use in qml, it means there will be a hundred of instances in main function. I think there must be more proper way to do it.
Secondly, if we register object by using qmlRegisterType and import in qml file, can i reach property of bar class after active qml changed ? Because as far as i know, object of bar class is created when corresponding qml is loaded.
Project.cpp
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
qmlRegisterType<bar>("MyLib", 1, 0, "Comp");
qmlRegisterType<bar2>("MyLib2", 1, 0, "Comp2");
QQmlApplicationEngine engine;
Foo foo;
engine.rooContext()->setContextProperty(QStringLiteral("foo"),&foo);
.
.
.
}
GlWindow.qml
import QtQuick 2.0
import MyLib 1.0
Comp
{
id:sample
}
GlWindow2.qml
import QtQuick 2.0
import MyLib2 1.0
Comp2
{
id:sample2
}
bar.h
class bar: public QObject
{
Q_OBJECT
public:
Product* product;
void initialize();//Initialize Gl
void render(); //paint product's context
}
bar2.h
class bar2: public QObject
{
Q_OBJECT
public:
Product* product2;
void initialize();//Initialize Gl
void render(); //paint product's context
}
I painted content of product on GlWindow.qml after that closed this qml and showed GlWindow2.qml. My problem starts here, how to transmit content of product to product2?