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. Is QIcon implementation leaking?
Forum Updated to NodeBB v4.3 + New Features

Is QIcon implementation leaking?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 388 Views 1 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.
  • L Offline
    L Offline
    leonardoMB
    wrote on last edited by leonardoMB
    #1

    QAbstractButton abs;
    abs->seticon(QIcon("hello.png"));

    As far as I understand the Creation of QIcon, it makes the d->ref to increment and the same happens when we setIcon. So QIcon("hello.png") would have 2 refs. Then we have a deref through the destruction of the object in the parameter and we have a d->ref with value 1 at the end, what makes the QIcon data to not be deleted. So How can I delete this data? I mean, I need deref it with the abs variable, but doesn't seem to have a way to do so. I think that there is something wrong here, any ideas?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Nothing's leaking here.
      QIcon is implicitly shared class and the button has an instance of it. When you set an icon like this a temporary icon is made (ref 1), then internal icon data is shared with the instance in the button (ref 2) and then the temporary is destroyed (back to ref 1). When the button is destroyed the icon member is destroyed too, so ref goes to 0 and releases the data. Again - nothing's leaking.

      If you want to remove that data earlier then just set a null icon, which will free the previous one.

      L 1 Reply Last reply
      3
      • Chris KawaC Chris Kawa

        Nothing's leaking here.
        QIcon is implicitly shared class and the button has an instance of it. When you set an icon like this a temporary icon is made (ref 1), then internal icon data is shared with the instance in the button (ref 2) and then the temporary is destroyed (back to ref 1). When the button is destroyed the icon member is destroyed too, so ref goes to 0 and releases the data. Again - nothing's leaking.

        If you want to remove that data earlier then just set a null icon, which will free the previous one.

        L Offline
        L Offline
        leonardoMB
        wrote on last edited by
        #3

        @Chris-Kawa Hi Chris, thanks for the answer. Would you know in Which destructor does it happen? I was using this oportunity to dive into the code so it would be more helpful

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The icon is a member of QAbstractButtonPrivate. It has no destructor specified, but it is implicit as part of the usual C++ class instance destruction process.

          L 1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            The icon is a member of QAbstractButtonPrivate. It has no destructor specified, but it is implicit as part of the usual C++ class instance destruction process.

            L Offline
            L Offline
            leonardoMB
            wrote on last edited by
            #5

            @Chris-Kawa Oh, you are totally right, I totally forgot about it! Just wondered about Qt destructors...

            1 Reply Last reply
            0

            • Login

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