用于 GUI 的 Qt Designer C++ 或 QML

2022-01-19 00:00:00 user-interface qt qml c++

我知道 QML 在 Qt 中的使用是相当新的,我想知道是否应该使用 Qt Designer 或 QML 来设计我的应用程序.我将使用 MVC 模式,如果我将 QML 用于 GUI,我主要担心的是它可能不容易集成到我的 C++ 应用程序的其余部分中.

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.

请随时提供您的个人建议,我将不胜感激.谢谢!

推荐答案

QML 主要用于移动平台.由于它的年轻和对各种平台界面约定的关注,它缺乏像按钮和组合框这样的标准控件(但请参阅 组件 项目).如果您使用移动设备,或者您的 UI 需要高度自定义的视觉样式,QML 可能值得考虑.为设计自定义控件的大量额外工作做好准备.在我看来,集成 QML 和 C++ 仍然相当粗糙.我个人建议仅将 QML 用于更简单的应用程序,仅在移动平台上,并且仅与 JavaScript 一起使用.在适当的情况下,我可能会考虑用 C++ 编写自定义 QML 元素.

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 的 C++ API 不会很快消失.它的设计还考虑到了桌面,并将更好地满足用户对桌面平台的期望.如果您使用的是桌面,我建议您坚持使用 C++ 和 Designer. 即使 QML 成熟了一点,它也可能不是大多数桌面应用程序的正确解决方案.

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.

看起来事情正在开始改变.我自己还没有尝试过新组件,文档似乎有点稀疏(或者至少不碍事),但这最终可能会消除在桌面上使用 QML 的最大障碍.从长远来看,这是否会得到支持还有待观察,但如果你愿意接受成为早期采用者的风险,我认为 QML 现在可能是桌面应用程序的可行选择.

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.

相关文章