QString 的目的是什么? [英] What's the purpose of QString?
问题描述
我是 C++ 和 Qt 的新手.我已经和 Qt Creator 混了几天,真正让我震惊的是 GUI 组件如何只接受 const QString&
而不是 string
或std::wstring
.为了与此保持一致,我一直试图从我的大多数函数调用中接受和返回 QString
,但是我发现自己在与 std::string
之间转换大量使用大多数标准图书馆设施.
I'm a newcomer to C++ and Qt. I've been messing around with Qt Creator for a few days, and what really struck me was how the GUI components only accepted a const QString&
rather than a string
or an std::wstring
. To stay consistent with this, I've been trying to accept and return QString
from most of my function calls, however I find myself converting to and from std::string
a lot to use most of the standard library facilities.
我的问题是,如果 std::string
是标准库的一部分,QString
的目的是什么?我想这对已经在使用 Qt 并且不想依赖 #include <string>
的人来说是有益的,但说实话,你需要 std::string
如果你想对你的应用程序做任何有用的事情.(这尤其适用于 QChar
,因为 char
是一个内置函数.)
My question here is, what's the purpose of QString
if std::string
is part of the standard library? I guess this would be beneficial to someone who was already using Qt and didn't want another dependency on #include <string>
, but to be honest you'll need std::string
if you want to do anything useful with your application. (This especially goes for QChar
, since char
is a builtin.)
有人可以向我解释为什么这不是重新发明轮子以及这如何有助于跨平台吗?
Can someone explain to me why this is not reinventing the wheel and how this helps being cross-platform?
推荐答案
我的问题是,如果
std::string
是标准库的一部分,QString
的目的是什么?
My question here is, what's the purpose of
QString
ifstd::string
is part of the standard library?
我能想到的原因:
QString
在std::string
出现之前已经成为 Qt 库方式的一部分.
QString
has been part of the Qt library way beforestd::string
came to life.
它的接口包括很多 Qt 特定的类.因此,QString
的用法不能轻易被 std::string
替代.
Its interface includes a lot of Qt specific classes. Hence, the usage of QString
cannot be easily replaced by std::string
.
它的界面比std::string
丰富了很多.
Its interface is a lot richer than std::string
.
这篇关于QString 的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!