用于 GUI 的 Qt Designer C++ 或 QML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4610073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Qt Designer C++ or QML for GUI
提问by clenemt
I know that the use of QML is quite new in QT and I was wondering if I should design my application using QTDesigner 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 reste of my C++ app.
我知道 QML 在 QT 中的使用很新,我想知道我是否应该使用 QTDesigner 或 QML 设计我的应用程序。我将使用 MVC 模式,如果我将 QML 用于 GUI,我的主要担忧是它可能不容易集成到我的 C++ 应用程序的其余部分中。
Feel free to give your personal advice, I would greatly appreciate it. Thank you!
请随时提供您的个人建议,我将不胜感激。谢谢!
采纳答案by Steve S
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 Componentsproject). If you're on mobile, or your UI requires a highly customized visual style, QML mightbe 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++.
QML 主要用于移动平台。由于它的年轻和对各种平台界面约定的关注,它缺乏像按钮和组合框这样的标准控件(但请参阅组件项目)。如果您使用的是移动设备,或者您的 UI 需要高度自定义的视觉样式,那么 QML可能值得考虑。为设计自定义控件的大量额外工作做好准备。在我看来,集成 QML 和 C++ 仍然很粗糙。我个人建议仅将 QML 用于更简单的应用程序,仅用于移动平台,并且仅用于 JavaScript。在适当的情况下,我可能会考虑用 C++ 编写自定义 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.
Qt 的 C++ API 不会很快消失。它还在设计时考虑了桌面,将更好地满足用户对桌面平台的期望。 如果您在桌面上,我建议您坚持使用 C++ 和 Designer。即使在 QML 稍微成熟之后,它也可能不是大多数桌面应用程序的正确解决方案。
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.
看起来事情开始发生变化。我自己还没有尝试过新组件,文档似乎有点稀少(或者至少,不方便),但这最终可能会消除在桌面上使用 QML 的最大障碍。从长远来看,这是否会得到支持还有待观察,但如果您愿意接受成为早期采用者的风险,我认为 QML 现在可能是桌面应用程序的可行选择。
回答by blam
It'd be worth trying a bit of QML to test whether it suits your needs.
值得尝试一些 QML 来测试它是否适合您的需求。
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.
如果您正在构建一个具有动态界面和动画的高度自定义的 UI,那么 QML 适合这项工作;如果您正在构建传统的桌面应用程序,那么您可能希望坚持使用 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.htmland http://doc.qt.io/archives/qt-4.7/qml-extending-tutorial-index.html.
关于 QML 和 C++ 之间的集成,QML 旨在与 C++ 代码轻松集成,许多 QML 应用程序使用某种 C++ 后端。将 C++ 对象注入 QML 接口或在 C++ 中编写自定义 QML 元素非常简单。看看http://doc.qt.io/archives/qt-4.7/qtbinding.html和http://doc.qt.io/archives/qt-4.7/qml-extending-tutorial-index.html。
回答by Daniel B. Chapman
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...
上述答案遗漏的一件事是 QML 在业务逻辑方面具有 JavaScript 的额外优势/劣势(如果需要)。我目前正在为桌面构建一个(中小型)大小的应用程序,现在我的 (2) alpha 用户喜欢它。我对框架的表现力以及我可以多快地设置和测试它印象深刻。总而言之,我发现它比 RAD 编辑器(设计器)更快,并且当我在做诸如悬停/验证等烦人的事情时,我喜欢将 JavaScript 作为 UI 的后备……
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.
我认为这取决于您对语言的熟悉程度。如果 C++ 是您的“首选”语言,那么您可能会喜欢设计师。如果您来自 Web(坦白说,我是一名 Java EE 工程师/MVC .NET 开发人员,做了很多前端工作),您会发现它令人耳目一新且快速。
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.
它还允许用户现在期望的一些响应能力。总的来说,我会给它一个巨大的加分。试一试——在同一时间范围内,你可能会很高兴,也很恼火。我仍然对一些事情感到生气(特别是 FileIO),但我一直在以一种我很少在桌面上做的方式享受事物的 GUI 方面。