Unsolved use of deleted function ‘Truck& Truck::operator=(const Truck&)’
-
Hi, I studied slots/signals so now I am making some practise.
I created the following code to do some tests.
But when I try to compile, I get error message/usr/include/qt5/QtCore/qmap.h:714: error: use of deleted function ‘Truck& Truck::operator=(const Truck&)’ lastNode->value = avalue; ~~~~~~~~~~~~~~~~^~~~~~~~ ^
truck.cpp https://pastebin.com/acTVgpUT
truck.h https://pastebin.com/EDYJ1M94
mainwindow.h https://pastebin.com/iD1gZcY6
mainwindow.cpp https://pastebin.com/FbCA0kAtWhere did I make a mistake? Thank you
-
Hi
QObjects are not copyable by design.
So when you say
QMap<QString, Truck> *trucksCollection;You will try to copy one into the list when adding a pair.
The normal solution is just to use
QMap<QString, Truck*> *trucksCollection;But be sure you manage the clean up since you most likely
will not give them a Qt parent to delete them for you. -
Hi,
To add to @mrjj, you don't needed to allocate trucksCollection on the heap. QMap manages its internal state there already.