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. Using QSharedPointer with QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

Using QSharedPointer with QGraphicsScene

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 315 Views
  • 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.
  • J Offline
    J Offline
    jkwok678
    wrote on last edited by
    #1

    Hi,

    I currently have normal QGraphicsPixmapItems that I add to the QGraphicsScene. When scene.clear is called, are all these objects deleted? If not would it make be better to use QSharedPointer, so that these objects would be deleted later on when scene.clear() is called?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @jkwok678 said in Using QSharedPointer with QGraphicsScene:

      When scene.clear is called, are all these objects deleted?

      It's clearly documented: QGraphicsScene::addItem(): "This scene takes ownership of the item."

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • J Offline
        J Offline
        jkwok678
        wrote on last edited by
        #3

        @Christian-Ehrlicher said in Using QSharedPointer with QGraphicsScene:

        "This scene takes ownership of the item."

        I don't quite understand what that means.

        jsulmJ 1 Reply Last reply
        0
        • J jkwok678

          @Christian-Ehrlicher said in Using QSharedPointer with QGraphicsScene:

          "This scene takes ownership of the item."

          I don't quite understand what that means.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @jkwok678 It answers your question: "When scene.clear is called, are all these objects deleted?". Since the scene takes the ownership it will delete the objects.

          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