Reputation: 185
I'm developing a C++ app using Qt. The app displays some various customized widgets that are made using QML. These widgets renders values using signal/slot system.
I was wondering what could be the best way to manage:
Upvotes: 2
Views: 182
Reputation: 49279
Depends on how complex your core logic is. If it is small and simple, do in QML. Even if it is not that small and simple, there can be quite a lot of benefits to using QML, as prototyping there is much, much faster and easier compared to C++. You don't have to recompile, you don't get crashes but fairly useful error messages. I find QML to be 5 to 10 times faster for prototyping than C++.
You can always move things over to C++ if you want better performance or memory efficiency, and it is a seamless plug and play transition, because you can use signals and slots in both worlds. It is usually faster to develop the algorithms in QML and port to C++ than to do in C++ from scratch. The downside is you have a different toolset on the low level, in C++ you can use Qt's core classes whereas in QML you will have to use JavaScript and its programming idioms. It really depends on how much experience you have with both, but with some practice, it is quite easy to translate QML to C++.
That being said, even if you opt for QML for the logic, it is always a good idea to have it as a separate layer from the GUI.
Unless you need QWidget
s for something else, there is absolutely no good reason to use QQuickWidget
, thus you can avoid the entire widgets module as a dependency. You do not need widgets to do the core logic in C++.
Upvotes: 2
Reputation: 2833
When you want to get things up and running fast doing the buisness logic in QML is a good way to go. But things will getting complicated when adding new features. After a while we got a lot of cascade-like callbacks by depending signals-slots in your QML-files. Special when mixing view- and buisness-code in one QML-file will make your code hard to maintain.
To avoid this using some kind of MVC or MVVM-pattern to separate buisness-logic from your view-code makes sence. And of course you can do the buissness-logic in QML. Separation of concerns helps a lot to keep your code-base understandable independent from your programming language.
When you have any performance-concerns regarding your buisness-logic using C++ for it is the best way to go ( made these experiences when starting with a first prototype in QML and needed to port it to an embedded platform ). And you can use C++ for some special QML-Elements as well of course.
So it strongly depends on your problem.
Upvotes: 3