Why does Qt have a β€œQ” version of standard C ++ objects (like QVector, QString, etc.)?

Why does Qt have a β€œQ” version for many standard objects / data structures in C ++? Is the argumentation described from a single source (i.e., you need to bind metadata to the formatting goal), or does it just depend on the specific case (for example, QString allows more language settings and QVectors allow "anything")?

Thanks!

+5
source share
3 answers
  • Qt containers precede STL containers, the original versions (in Qt 1 or Qt 2 or something else) were created when there were no standard C ++ alternatives. In addition, the adaptation of STL for all (at that time) supported compilers was gradual, and Qt was cross-platform oriented, so keeping your own implementation guaranteed that it would work the same everywhere. And getting rid of Qt's native types now, for the next major version of Qt, would mean an impossible amount of porting operations, so such a new version would be effectively dead upon arrival.

  • Qt containers are actually different, they use implicit data exchange with Copy-on-write semantics and reference counting. The advantages and disadvantages of this approach go beyond this, but the Qt implementation is good, at least for using the Qt Framework, because of the way signals and slots work (especially in the connection queue).

+8
source

This is because Qt precedes the first C ++ standard. Moreover, only a few years later, you could reasonably expect that various compilers will support the standard library without unpleasant angular cases. By that time, Q-containers (and other classes, such as QString) had a solid base in the code base, and they provided functionality quite different so that there was a simple way to replace them.

+3
source

To add to the other answers, QString fundamentally different from std::string because it is specifically designed to store a Unicode string. Although std::string may contain a Unicode string encoded in UTF-8, some platforms (such as Windows) do not support UTF-8.

For historical reasons, QString internally represents string data in UTF-16, but has conversion methods for outputting string data in other formats, including UTF-8.

When creating a Qt application, it is best to stick to QString , since all its APIs use Qt, and you do not have to deal with encoding / re-encoding from std::string or std::wstring , the later of which has different meanings on different platforms.

+3
source

Source: https://habr.com/ru/post/1259067/


All Articles