C++ 混合 Qt 和 Boost
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/360160/
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
Mixing Qt and Boost
提问by dwj
I'm looking at starting a project in C++ using the Qt 4 framework (a cross-platform GUI is required). I've heard great things about the Boost libraries from friends and online. I've started reading up on both and wanted to ask a cursory question before I got too deep: Are these two development "systems" mutually exclusive?
我正在考虑使用 Qt 4 框架(需要跨平台 GUI)在 C++ 中启动一个项目。我从朋友和网上听说过关于 Boost 库的好消息。我已经开始阅读两者,并想在深入了解之前提出一个粗略的问题:这两个开发“系统”是否相互排斥?
My initial searching and reading shows some overlap in the signal handling, custom build systems, and other low-level primitives.
我最初的搜索和阅读显示信号处理、自定义构建系统和其他低级原语中有一些重叠。
Does it make sense to use them both in the same project?
在同一个项目中使用它们是否有意义?
采纳答案by Martin Beckett
Yes it makes perfect sense. I would generally prefer using the boost/stdlib functions where possible rather than their Qt alternatives.
是的,这是完全有道理的。我通常更喜欢在可能的情况下使用 boost/stdlib 函数而不是它们的 Qt 替代方案。
It makes the code easier to port to the next framework.
It makes is easier for new non-Qt programmers to get upto speed.
Boost has some great functionality and is getting more all the time.
它使代码更容易移植到下一个框架。
它使新的非 Qt 程序员更容易上手。
Boost 有一些很棒的功能,并且一直在增加。
note: strings to/from widgets are probably the main exception - inside the GUI I would use Qt strings to save confusing casts everywhere.
注意:小部件之间的字符串可能是主要的例外——在 GUI 中,我会使用 Qt 字符串来保存无处不在的令人困惑的强制转换。
回答by ?zgür
This papercompares signal slotsmechanism in QT and Boost::Signalvery decently. It is a must read for those who are a bit curious of this mix.
这篇论文非常体面地比较了 QT 和Boost::Signal 中的信号槽机制。对于那些对这种组合有点好奇的人来说,这是必读的。
回答by Tiberiu Ana
Especially since you are going cross-platform, you should have a nicely layered architecture, with the business logic and data access as removed as possible from the GUI. In this case, it would make sense to use Boost when writing the backend of your application, and only jump to Qt for the frontend, with the mandatory pile of casts done in the glue.
特别是因为您要跨平台,所以您应该有一个很好的分层架构,尽可能从 GUI 中删除业务逻辑和数据访问。在这种情况下,在编写应用程序的后端时使用 Boost 是有意义的,并且只在前端跳转到 Qt,在胶水中完成强制性的一堆强制转换。
If your "engine" is separate from your GUI choice, you will be able to swap out Qt for something else in the future (native libraries perhaps) with minimal effort.
如果您的“引擎”与您的 GUI 选择是分开的,您将能够在未来以最小的努力将 Qt 换成其他东西(可能是本机库)。
回答by mxcl
We (Last.fm) use them both together, though we only just started to do so, and so haven't a good deal of experience yet. So far everything is fine though :)
我们(Last.fm)同时使用它们,虽然我们才刚刚开始这样做,所以还没有很多经验。到目前为止一切都很好:)
回答by Daniel James
There are potential problems with using Boost.Signals alongside QT. These are documented in the Boost.Signals FAQ.
将 Boost.Signals 与 QT 一起使用存在潜在问题。这些记录在Boost.Signals FAQ 中。
回答by Pietro
Consider that Boost Signals2are available, and they are thread safe.
考虑到Boost Signals2可用,并且它们是线程安全的。