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. [SOLVED] memory get exhausted due to setting Icon on a Tool-Button
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] memory get exhausted due to setting Icon on a Tool-Button

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.5k 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.
  • maweloM Offline
    maweloM Offline
    mawelo
    wrote on last edited by mawelo
    #1

    Hello !

    I am using the following code to set the Icon on a Tool-Button:

     QIcon sc;
     sc.addPixmap(screen->grabWindow(0,-1,-1,screen->geometry().width(),screen->geometry().height()).scaled(ui->toolButton_ScreenShot->width(),ui->toolButton_ScreenShot->height(),Qt::KeepAspectRatio,Qt::SmoothTransformation));
     ui->toolButton_ScreenShot->setIcon(sc);
     ui->toolButton_ScreenShot->setIconSize(QSize(ui->toolButton_ScreenShot->width(),ui->toolButton_ScreenShot->height()));
    

    Every time the Icon gets renewed memory gets exhausted. This also happen if I use a file like

    sc.addFile(QStringLiteral("../logo.png"), QSize(), QIcon::Normal, QIcon::Off);

    Is this an issue caused by the way I doing this or is this a bug ?

    Best Regards Martin

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

      Hi,

      Do you mean that if you call that code once you're out of memory ?

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

      maweloM 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Do you mean that if you call that code once you're out of memory ?

        maweloM Offline
        maweloM Offline
        mawelo
        wrote on last edited by
        #3

        @SGaist every time I call this code I loose memory. Seems like the old allocation for the Pixmap will not made free.
        This was testes on Mac OS X. I will check this issue for Linux....didn't do that yet.

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

          Do you have any allocation around that code ?

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

          maweloM 1 Reply Last reply
          0
          • SGaistS SGaist

            Do you have any allocation around that code ?

            maweloM Offline
            maweloM Offline
            mawelo
            wrote on last edited by mawelo
            #5

            @SGaist No. nothing more around with any allocation of memory. Here the complete code (called by the timer):

            void Dog::ScreenShooter()
            {
                int scnum = ui->spinBox_screen_num->value();
            
                QList<QScreen*> sl = QGuiApplication::screens();
            
                QScreen *screen=NULL;
            
                if(  scnum  < sl.size() )
                {
                 screen = sl.at(scnum);
                 ui->label_screen->setText(QString("Screen(%1)").arg(screen->name()));
                }
                else
                {
                 screen = QGuiApplication::primaryScreen();
                 ui->label_screen->setText(QString("primaryScreen(%1)").arg(screen->name()));
                }
            
                if(screen)  // this is play code and the redundant lines will go later !
                {
                 //FIXIT: memory get exhausted !
                 QIcon sc;
                 sc.addPixmap(screen->grabWindow(0,-1,-1,screen->geometry().width()+200,screen->geometry().height()+200).scaled(ui->toolButton_ScreenShot->width(),ui->toolButton_ScreenShot->height(),Qt::KeepAspectRatio,Qt::SmoothTransformation));
                 ui->toolButton_ScreenShot->setIcon(sc);
                 ui->toolButton_ScreenShot->setIconSize(QSize(ui->toolButton_ScreenShot->width(),ui->toolButton_ScreenShot->height()));
                }
                else
                {
                    QIcon icon2;
                    icon2.addFile(QStringLiteral("../fail.png"), QSize(), QIcon::Normal, QIcon::Off);
                    ui->toolButton_ScreenShot->setIcon(icon2);
                    ui->toolButton_ScreenShot->setIconSize(QSize(ui->toolButton_ScreenShot->width(),ui->toolButton_ScreenShot->height()));
                }
            }
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Did you check the pixmap size ?

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

              maweloM 1 Reply Last reply
              0
              • SGaistS SGaist

                Did you check the pixmap size ?

                maweloM Offline
                maweloM Offline
                mawelo
                wrote on last edited by
                #7

                @SGaist I found my mistake !

                    QIcon sc;
                     QPixmap pm=screen->grabWindow(QWidget::winId(),0,0,screen->geometry().width(),screen->geometry().height()).scaled(ui->toolButton_ScreenShot->width(),ui->toolButton_ScreenShot->height(),Qt::KeepAspectRatio,Qt::SmoothTransformation);
                     sc.addPixmap(pm);
                     ui->toolButton_ScreenShot->setIcon(sc);
                     ui->toolButton_ScreenShot->setIconSize(QSize(ui->toolButton_ScreenShot->width(),ui->toolButton_ScreenShot->height()));
                

                It was not good to use -1 for x and y parameter of grabWindow. Now with this call everything works as expected. So it was a Layer 8 Problem :-)
                But thank you very much for your help !!!

                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