What are the pros and cons of using Qt containers (
QVector, etc.) over their STL equivalent?
I can see one reason to prefer Qt:
QVariantand then a
QSettings(with some limitation though, only
QHashwhose keys are strings are accepted).
Is there any other?
Edit: Assuming the application already relies on Qt.
I started by using
std::(w)string and the STL containers exclusively and converting to/from the Qt equivalents, but I have already switched to
QString and I find that I'm using Qt's containers more and more.
When it comes to strings,
QString offers much more complete functionality compared to
std::basic_string and it is
completely Unicode aware. It also offers an efficient COW implementation, which I've come to rely on heavily.
QString, which is extremely useful when it comes to using Qt's
foreachmacro (which does a copy) and when using meta-types or signals and slots.
std::stringCOW controversy). Some STL implementations are especially bad.
The QTL has a different philosophy from the STL, which is well summarized by J. Blanchette: "Whereas STL's containers are optimized for raw speed, Qt's container classes have been carefully designed to provide convenience, minimal memory usage, and minimal code expansion."
The above link provides more details about the implementation of the QTL and what optimizations are used.
This is a difficult to answer question. It can really boil down to a philosophical/subjective argument.
That being said...
I recommend the rule "When in Rome... Do as the Romans Do"
Which means if you are in Qt land, code as the Qt'ians do. This is not just for readability/consistency concerns. Consider what happens if you store everything in a stl container then you have to pass all that data over to a Qt function. Do you really want to manage a bunch of code that copies things into/out-of Qt containers. Your code is already heavily dependent on Qt, so its not like you're making it any more "standard" by using stl containers. And whats the point of a container if everytime you want to use it for anything useful, you have to copy it out into the corresponding Qt container?