Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How to create a container with reference objects in Qt?

    General and Desktop
    3
    4
    53
    Loading More Posts
    • 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.
    • M
      Mikeeeeee last edited by

      Good afternoon.
      Made this vector:

      QVector <MoveItem> vectorMoveItem;
      

      Separately create objects of the class:

      MoveItem *item = new MoveItem(); // Create a graphic element
      

      In vector vector Move Item to record the item objects?
      It doesn't work:

      vectorMoveItem.append(*item);
      
      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        Store pointers, not objects

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 1
        • M
          Mikeeeeee last edited by

          It's work

          QVector <MoveItem *> vectorMoveItem;
          

          But how to address the element of the vector?
          It doesn't work:

          vectorMoveItem[3]
          
          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            Did you put enough elements in this vector ?

            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 Reply Quote 0
            • First post
              Last post