51

I know that the use of QML is quite new in Qt and I was wondering if I should design my application using Qt Designer or QML. I will be using a MVC pattern and my main concern if I use QML for the GUI is that it might not be easy to integrate inside the rest of my C++ app.

Feel free to give your personal advice, I would greatly appreciate it. Thank you!

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
clenemt
  • 793
  • 1
  • 7
  • 20
  • Here http://sharedrealitynews.blogspot.com/2012/02/building-qml-desktop-components-with.html is a tutorial on how to setup and compile QML-Desktop-Components with CMake for Visual Studio , the tutorial contains a zip-File with complete startup code which should work out of the box. Hope it helps –  Mar 05 '12 at 09:39
  • Related: [QML in C++ app or vice versa](http://stackoverflow.com/q/18205234/514235) – iammilind May 15 '17 at 09:33

3 Answers3

47

QML is primarily intended for mobile platforms. Due to its youth and its concern for varied platform interface conventions, it lacks standard controls like buttons and combo boxes (but see the Components project). If you're on mobile, or your UI requires a highly customized visual style, QML might be worth considering. Be prepared for a lot of extra work in designing custom controls. Integrating QML and C++ is still pretty rough in my opinion. I would personally recommend using QML only for simpler apps, only on mobile platforms, and only with JavaScript. Under the right circumstances I might consider writing custom QML elements in C++.

Qt's C++ API isn't going away anytime soon. It's also designed with the desktop in mind and will do a better job of meeting user expectations on desktop platforms. If you're on the desktop, I would recommend sticking to C++ and Designer. Even after QML matures a bit, it probably won't be the right solution for most desktop apps.

Update!

It looks like things are beginning to change. I haven't tried the new components myself yet, and documentation seems a little sparse (or at least, out of the way), but this could eventually remove the greatest barrier to using QML on the desktop. It remains to be seen whether this will get support in the long term, but if you're willing to accept the risk of being an early adopter, I think QML may now be a viable choice for desktop apps.

Linville
  • 3,613
  • 1
  • 27
  • 41
Steve S
  • 5,256
  • 1
  • 29
  • 26
  • 10
    I see QML as a cross-platform (and entirely more readable!) version of WPF/XAML. There's nothing at all that makes it mobile specific. – Dynite Feb 22 '11 at 13:27
  • @Dynite: Not inherently, but mobile is what Nokia is (was?) pushing it for, and that's where it's currently most comfortable. For example, the standard QML components are designed for touch-screens rather than mice. – Steve S Feb 22 '11 at 15:32
  • Also, from http://doc.qt.nokia.com/4.7-snapshot/qtquick.html -- "Qt Quick is a collection of technologies that are designed to help developers create the kind of intuitive, modern-looking, fluid user interfaces that are increasingly used on **mobile phones, media players, set-top boxes and other portable devices**." (emphasis added) – Steve S Feb 22 '11 at 15:33
  • 1
    @Steve "that's where it's currently most comfortable". I don't think that is substantiated by the facts. The text you've pasted is just marketing material to show that is can be used anywhere. – Dynite Feb 22 '11 at 15:37
  • @Dynite: That's fair, but you didn't address the touch-screen preference of the standard elements. Also, the Components project seems to be primarily supporting mobile platforms -- I don't see any equivalent support for mimicking desktop GUI styles. – Steve S Feb 22 '11 at 16:43
  • Would you give this any more weight than the last link?: http://labs.qt.nokia.com/2010/09/10/building-the-future-reintroducing-the-qt-quick-components/ "QWidget-based UIs will reman the primary architecture to use for Desktop applications" – Steve S Feb 22 '11 at 16:44
  • Even if that is marketing talking, I think it's worth considering, because it indicates the direction the company is likely to go with each technology. – Steve S Feb 22 '11 at 16:46
  • 1
    This answer may be edited to reflect the fact that it is nos easy to mix Qt C++ API with QML (in both ways). So, for desktop, you can start with an upper level C++ Widgets, and inside it, add some part designed with QML if you need beautiful, fancy stuff. – Korchkidu Dec 20 '13 at 07:28
15

It'd be worth trying a bit of QML to test whether it suits your needs.

If you are building a highly custom UI with dynamic interfaces and animations then QML fits the job; if you are building a traditional desktop application then you will probably want to stick with the Qt C++ API.

In regards to integration between QML and C++, QML is designed to be easily integrated with C++ code, and many QML applications use some sort of C++ backend. It is straightforward to inject C++ objects into a QML interface, or write custom QML elements in C++. Have a look at http://doc.qt.io/archives/qt-4.7/qtbinding.html and http://doc.qt.io/archives/qt-4.7/qml-extending-tutorial-index.html.

Christophe Weis
  • 2,518
  • 4
  • 28
  • 32
blam
  • 1,125
  • 9
  • 5
13

One thing missed by the above answers is that QML has the added advantage/disadvantage of JavaScript for business logic (if needed). I am currently building a (small to medium) sized application for the desktop and right now my (2) alpha users enjoy it. I'm impressed with the expressiveness of the framework and how quickly I can get it up and tested. All in all I find it faster to work with than a RAD editor (designer) and I enjoy having JavaScript as a fallback on my UI when I'm doing annoying things like hovers/validation etc...

I think it is a matter of how comfortable you are with the language. If C++ is your "go to" language than you'll probably favor the designer. If you're coming from the Web (confession, I'm a Java EE engineer/MVC .NET dev doing a lot of front end) you'll find it refreshing and fast.

It also allows for some responsiveness that users expect these days. Overall I'd give it a huge plus. Give it a try--you'll probably be rather please and rather annoyed in the same time frame. I'm still angry about a couple things (FileIO in particular) but I've been enjoying the GUI side of things in a way I rarely do on the desktop.

Daniel B. Chapman
  • 4,647
  • 32
  • 42