[Qt-interest] Problem with qSort and QObjects
Stephen Kelly
steveire at gmail.com
Tue Feb 16 13:10:11 CET 2010
Thiago Macieira wrote:
> 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.
It is also mentioned here:
http://doc.trolltech.com/4.6/containers.html
>
> 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.
>
More information about the Qt-interest-old
mailing list