将 Qt 与 STL 和 Boost 混合 - 有没有任何桥梁可以使它变得简单?
是否有任何桥梁可以使 Qt 与 STL 和 Boost 的混合尽可能无缝且简单?
这是混合 Qt 和 Boost 的后续内容,其中没有给出如何完成此操作的具体答案。
Are there any bridges to make mixing Qt with STL and Boost as seamless and easy as possible?
This is a followup to Mixing Qt and Boost, where no specific answers how to accomplish this were given.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你需要什么桥梁?
您可以将所有 Qt 容器类与 std 算法一起使用。
大多数时候我更喜欢 Qt 容器类,因为我确信它们使用写时复制习惯用法(恒定时间操作)。 Qt 的 foreach 函数创建容器的副本,因此您可以确定它是一个恒定时间操作,这很好。
如果 Qt 信号槽机制变慢,您可以切换到升压替代方案。
Qt 信号/槽的伟大之处在于两个线程之间的信号/槽连接。
QtConcurrent 与 BOOST.Lambda 配合得很好
对于“共享”子父关系,我使用这个辅助函数。
Boost.serialize 不支持 Qt 容器,您必须自己编写序列化函数。
我希望在 Qt 流类和 Boost.archive 之间建立一座桥梁。
这是我的 QList 序列化模板,您可以弄清楚其余的...
如果您希望 Boost.Bind 将 QPointer 作为普通指针(如共享指针)处理:
使用
QIODevice
where astd ::stream
是必需的示例
What bridges do you need?
You can use all the Qt container classes with std algorithms.
Most of the time I prefer the Qt container classes because I'm sure they use the copy-on-write idiom (constant time operation). Qt's foreach function creates a copy of the container so its nice that you know for sure it is a constant time operation.
If the Qt signal slot mechanism is to slow you can switch to the boost alternative.
The great thing about Qt signal/slot is the signal/slot connection between two threads.
QtConcurrent works great with BOOST.Lambda
For "shared" child-parent relationship I use this helper function.
Qt containers are not supported by Boost.serialize, you'll have to write the serialize functions yourself.
I would love a bridge between the Qt streaming classes and Boost.archive.
Here is my QList serialization template you can figure out the rest of them ...
If you want Boost.Bind to handle QPointer as a normal pointer (like shared_ptr):
Using
QIODevice
where astd::stream
is neededExample
到底是什么问题?
如果您愿意,可以忽略所有 Qt 集合类并使用 STL 等效项。
同样,您可以使用 Boost 的跨平台文件/网络库。
使用 Qt 自己的主要原因可能是 boost 不一定广泛可用,尤其是在移动设备上。 对于简单任务,Boost 的一些库使用起来比 Qt 的库稍微复杂一些。
What exactly is the problem?
You can ignore all the Qt collection classes if you want and use STL equivalents.
Similarly you can use Boost's cross platform file/network libs.
The main reason to use Qt's own is probably that boost isn't necessarily that widely available, especially on mobile devices. Some of Boost's libs are a little more complicated to use than the Qt ones for simple tasks.
一般来说,如果您坚持使用 QT Collection 类而不是我们的 STL,那么在使用 QT 时您会表现得更好。 Qt、STL 或 Boost 本身并不妨碍相互使用 then。
使用智能指针时必须小心,QT 具有父/子关系,可以处理对象的销毁,当对象受 Qt 控制时释放对象将使您崩溃。
In general you are going to fare better when using QT if you stick to the QT Collection classes rather than us STL. There is nothing per se in Qt, STL or Boost that would preclude using then within each other.
You would have to be careful when using smart pointers QT has parent/child relationship that can take care of destruction of objects, deallocating objects when they under control of Qt will make you crash.