[Qt-creator] Crazy idea 202: main.cpp wizards
Jason H
jhihn at gmx.com
Wed Apr 10 17:39:21 CEST 2019
There are some things that just always happen in main.cpp, this is particularly true for QML stuff that happens for engine initialization.
It would be cool if:
1. There was a wizard/automated way to add a QObject-derived class to the main.
1a. Insert #include <QQmlEngine> if needed
1b. insert qmlRegisterType<MyObject>("com.mycompany.%PROJECTNAME%", 1, 0, "MyObject");
2. Support the other QML registration functions qmlRegisterSingletonType
3. Register Enums and the like.
There may be other non-QML template stuff appropriate in main. I don't know if this is hard or not but if there was a section:
/* Begin QtCreator Wizard Generated code. Do not edit, code managed by QtCreator */
qmlRegisterType<MyObject>("com.mycompany.%PROJECTNAME%", 1, 0, "MyObject");
/* End QtCreator Wizard Generated code */
I also saw on stack exchange https://stackoverflow.com/questions/20089196/how-to-access-c-enum-from-qml
where the example has a static declareQML() function that registers itself. I don't know if this is preferred or not. Seems like more code and would make something like this harder. But if that is to continue, maybe have a thing in the class creation wizard to do that, or use that as the place to trigger the qmlRegisterType in main.cpp?
More information about the Qt-creator
mailing list