Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Qt have a 'Q' version of standard C++ objects (e.g. QVector, QString, etc.)?

Tags:

c++

qt

Why must Qt have a 'Q' version for many standard objects/data structures in C++? Does the reasoning spawn from one source (i.e. there needs to be attached meta data for formatting purpose), or is it something that just depends on the case (e.g. QString allows for more language settings and QVectors allow for 'whatever')?

Thanks!

like image 552
Izzo Avatar asked Oct 31 '16 20:10

Izzo


1 Answers

  1. Qt containers precede STL containers, original versions (in Qt 1 or Qt 2 or something) were created when there were no standard C++ alternatives. Also, adaptation of the STL for all (at that time) supported compilers was gradual, and Qt was geared toward being cross-platform, so keeping its own implementation guaranteed it would work the same everywhere. And getting rid of the Qt's own types now, for next major Qt version, would mean impossible amount of porting work, so such a new version would effectively be dead on arrival.

  2. Qt containers are actually different, they use implicit data sharing with Copy-on-write semantics and reference counting. Advantages and disadvantages of this approach are beyond the scope of this, but Qt implementation is good at least for the Qt Framework use, due to how signals and slots work (especially queued connections).

like image 65
hyde Avatar answered Sep 21 '22 02:09

hyde