Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. use of deleted function ‘Truck& Truck::operator=(const Truck&)’
Forum Updated to NodeBB v4.3 + New Features

use of deleted function ‘Truck& Truck::operator=(const Truck&)’

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cat_
    wrote on last edited by
    #1

    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/FbCA0kAt

    Where did I make a mistake? Thank you

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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.

      1 Reply Last reply
      4
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        To add to @mrjj, you don't needed to allocate trucksCollection on the heap. QMap manages its internal state there already.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved