reuse of custom C++ class
-
I use the same C++ chart class multiple times in a QML desktop application. I currently use multiple copies of the class with slightly different names and register them as follows:
ret = qmlRegisterType<MyClass0>("QwtQuick2", 1, 0, "MyClass0");
ret = qmlRegisterType<MyClass1>("QwtQuick2", 1, 0, "MyClass1");
ret = qmlRegisterType<MyClass2>("QwtQuick2", 1, 0, "MyClass2");
MyClass0 myclass0;
MyClass1 myclass1;
MyClass2 myclass2;Here I connect the signals and slots to the classes for each chart.
This method functions as needed but I would prefer to not maintain many copies of the same class. Is there an alternative method?
Thanks,
Aaron -
Are you using these in QML?
Just do this in C++:qmlRegisterType<MyClass>("QwtQuick2", 1, 0, "MyClass");
Then in qml:
import QwtQuick2 1.0 ... MyClass { id: myclass0 } MyClass { id: myclass1 } MyClass { id: myclass2 }
You can connect signals in qml via Connections, through on<signal name> callbacks, or actual connect calls to attach to functions in qml.
What are you connecting to these objects?
-
Hi,
What are the differences between these classes ?
-
Are you using these in QML?
Just do this in C++:qmlRegisterType<MyClass>("QwtQuick2", 1, 0, "MyClass");
Then in qml:
import QwtQuick2 1.0 ... MyClass { id: myclass0 } MyClass { id: myclass1 } MyClass { id: myclass2 }
You can connect signals in qml via Connections, through on<signal name> callbacks, or actual connect calls to attach to functions in qml.
What are you connecting to these objects?