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. QPushButton::setIcon produces memory leaks
Forum Updated to NodeBB v4.3 + New Features

QPushButton::setIcon produces memory leaks

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.8k 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.
  • S Offline
    S Offline
    stvokr
    wrote on last edited by
    #1

    Hi all,

    I have found a possible bug.
    When using the QPushButton::setIcon() function multiple times the memory is increasing with Qt 5.8 on Windows 10.
    I checked some cases with my little test program here. To see the effect I called the slot multiple times with a timer.

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QTimer* timer = new QTimer( this );
        connect( timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
    
        timer->start( 10 );
    }
    
    void MainWindow::onTimeout()
    {
        ui->pushButton->setIcon( QIcon( ":/images/icon.png" ) );
    }
    

    I analyzed some cases:

    This is working with Qt 4.8 but not with 5.8:
    With Qt 5.8 memory is increasing with 200 kb/s.

    ui->pushButton->setIcon( QIcon( ":/images/icon.png" ) );
    

    This is working on Qt 4.8 and 5.8 (no memory leaks):

    ui->pushButton->setIcon( QIcon( QPixmap( ":/images/icon.png" ) ) );
    

    I used Qt 4.8 with msvc2008.
    I used Qt 5.8 with msvc2015 and mingw. Both same behavior.
    Can someone confirm this?

    regards
    Oliver

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

      Hi
      Can you link to the complete test project ?
      So we use same icons etc.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stvokr
        wrote on last edited by
        #3

        My test project:
        https://www.file-upload.net/download-12297594/TestGUI.7z.html

        1 Reply Last reply
        0
        • G Offline
          G Offline
          galaxyHu
          wrote on last edited by
          #4

          I test the code "ui->pushButton->setIcon(QIcon(":/backword.png"));" in the timeout slot,and timer start by 10ms,it is ok.The memory is ok.

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

            Win 7, mingw Qt5.7.1
            Also see 200 kb increase. pr tick.
            But it never went over 40k. even running for long time.
            So not leak in 5.7

            //your code here

            1 Reply Last reply
            1
            • S Offline
              S Offline
              stvokr
              wrote on last edited by
              #6

              OK, no leak. I have also recognized this in further tests. And if you stop the timer after 10000 ticks you can see that the memory is somehow decreasing. Perhaps the garbage collector is doing his job with a loooong delay.

              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