[Qt-interest] Problem with qSort and QObjects
Thiago Macieira
thiago at kde.org
Tue Feb 16 08:30:17 CET 2010
Em Terça-feira 16. Fevereiro 2010, às 07.11.38, Carl Snellman escreveu:
> Now, would it make sense to add a few lines to qSort(..) docs to
> describe the requirement that the objects must implement copy
> constructor also? I spent several hours with this... Or is this common
> knowledge that I have just missed on my exploration journey with Qt?
No, because it's not a qSort requirement. It's a QList requirement, which is
shared with all the other container classes.
For a container class, its element type must be default-constructible,
copyable, assignable, destructible and assignable. For QMap, it must also be
orderable (operator<).
If you look at the error message you posted:
In constructor 'Account::Account(const Account&)':
main.cpp:7: instantiated from 'T QList<T>::value(int) const [with T =
Account]'
main.cpp:35: instantiated from here
/home/maemo/qtsdk-2010.01/qt/include/QtCore/qobject.h:309: error:
'QObject::QObject(const QObject&)' is private
It's telling you that the copy constructor is private. That means QObject is
not copyable. So the compiler is telling you everything you need to know.
Maybe this is the first time you ran into that error. Fair enough, the first
time is always the most difficult one. But now you know.
--
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/20100216/a7f42957/attachment.bin
More information about the Qt-interest-old
mailing list