[Qt-interest] Problem with qSort and QObjects

Thiago Macieira thiago at kde.org
Sun Feb 14 18:33:46 CET 2010


Em Domingo 14. Fevereiro 2010, às 16.37.42, Florian VICHOT escreveu:
> Sorry just realised I didn't really answer your second question.
> 
> > 1) What I need to do to get the QObject version working? qSort docs
> > say that the items need to implement operator<(), but clearly that is
> > not enough.
> 
> BTW, using QObject by value is a bad idea. I gave the fix to make it
> work, but it's not a good idea in most cases. If you copy QObject using
> the methods I gave you, it won't copy along signal/slot connections,
> etc, since QObject(const QObject& o) is not called.

The proper solution to this problem is to not use QObject at all.

I see nothing in Carl's Account class that requires a QObject. There are no 
signals, no slots, no properties, it doesn't require the parent-child 
ownership tree.

If you look at it, you notice that it only makes sense to copy the object 
*because* it doesn't require those things. Because if it did require them, the 
copying would shear the information -- and that's why QObject-derived classes 
cannot be copied.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100214/2ae5377d/attachment.bin 


More information about the Qt-interest-old mailing list