[Development] Upgrading the sources to C++11 keywords (Q_NULLPTR, etc.)

Rutledge Shawn Shawn.Rutledge at theqtcompany.com
Mon Feb 9 14:21:44 CET 2015


On 9 Feb 2015, at 13:42, Smith Martin <Martin.Smith at theqtcompany.com> wrote:

>>> Everyone wishing to use a QMap should implement one before
>>> using it for the first time. Then you'd see what you inflict on the world.
> 
> If that sentiment is valid, then we owe it to our users who are contemplating using a QMap to explain to them when and why a QMap should be used and when and why a QVector should be used instead.  
> 
>> IMHO: A lot of this is information you find in a CS course or in a book.
>> Not in the Qt documentation.
> 
> I came out of a CS course, but I would find that information helpful. Plus, we hope to attract users to Qt who didn't come out of a CS course. 

+1 to that.

I also didn’t think that QMap was so bad, because O(log n) doesn’t sound bad; and I don’t remember having written a red-black tree from scratch before, either.  The docs also say that QHash is faster but QMap is sorted.  So my inclination is if I really want the built-in sorting (maybe because I want to be able to iterate the keys or values in a predictable order), and I want to map arbitrary keys to arbitrary values, where the two are not related, or when the value contains the key but also contains other stuff, then I’d tend to use a QMap.  If the value does not contain the key, and you want to use a sorted vector instead, you would have to create an artificial “node” class (or use QPair) just to put the key together with the value so that you can put it into the vector, right?  If that is a better way, maybe we should have a wrapper class to make it easy.  The help about QVector does not even contain the word “sort”, so you have to know to use std::sort (or by reading the qSort doc where it says to use std::sort instead).  Nor do we have any classes called QSortedSomething.

Or should we recommend to use more STL structures instead of Qt ones?  But the advantage of Qt data structures is the implicit sharing.




More information about the Development mailing list