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. WI see memory leakage when a trigger a signal and empty slot is executed in qt?

WI see memory leakage when a trigger a signal and empty slot is executed in qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 924 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.
  • stackprogramerS Offline
    stackprogramerS Offline
    stackprogramer
    wrote on last edited by
    #1

    Hi, I created a simple application and this application has only a button and a LineEdit...When I click on the start button I see that application memory increases step by step in case I clicked on the button...Is this memory leakage?
    Why do a simple signal and empty slot cause this problem? see screenshots...

    void MainWindow::on_pushButtonStart_clicked()
    {
     if(ui->lineEditFileSelected->text().isEmpty())
         {
           
            return;
         }
    }
    
    

    Screenshot from 2022-08-07 19-57-47.png

    Screenshot from 2022-08-07 19-58-03.png
    Screenshot from 2022-08-07 19-58-24.png

    JonBJ 1 Reply Last reply
    0
    • stackprogramerS stackprogramer

      Hi, I created a simple application and this application has only a button and a LineEdit...When I click on the start button I see that application memory increases step by step in case I clicked on the button...Is this memory leakage?
      Why do a simple signal and empty slot cause this problem? see screenshots...

      void MainWindow::on_pushButtonStart_clicked()
      {
       if(ui->lineEditFileSelected->text().isEmpty())
           {
             
              return;
           }
      }
      
      

      Screenshot from 2022-08-07 19-57-47.png

      Screenshot from 2022-08-07 19-58-03.png
      Screenshot from 2022-08-07 19-58-24.png

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @stackprogramer
      What is the usage after you have pressed it 100 times?

      1 Reply Last reply
      0
      • stackprogramerS Offline
        stackprogramerS Offline
        stackprogramer
        wrote on last edited by
        #3

        Screenshot from 2022-08-07 21-55-41.png

        Gradually used memory volume is increased... even for 100 times... and ...so on

        1 Reply Last reply
        0
        • stackprogramerS Offline
          stackprogramerS Offline
          stackprogramer
          wrote on last edited by
          #4

          There is no One that can help me for understanding this strange problem?

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

            Provide a minimal, compilable example - your code snippet does not cause a leak.

            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
            2
            • stackprogramerS Offline
              stackprogramerS Offline
              stackprogramer
              wrote on last edited by
              #6

              @Christian-Ehrlicher I attached a minimal application.
              You should compile it and only click on the tool button to select a file or empty one...
              For me, my memory increased every time I did it.

              Screenshot from 2022-08-12 10-14-10.png
              You can dowload it from below link
              https://www.mediafire.com/file/ji6o7npfvjgwyyi/Qt-Test.zip/file

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

                Your example does not leak anything. Use a proper memory leak checker like e.g. valgrind or similar. ps ux or the windows task manager are not sufficient to detect memory leaks.

                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
                2
                • stackprogramerS Offline
                  stackprogramerS Offline
                  stackprogramer
                  wrote on last edited by stackprogramer
                  #8

                  @Christian-Ehrlicher said in WI see memory leakage when a trigger a signal and empty slot is executed in qt?:

                  valgrind

                  So after some time that I use my program after 10000 clicks.... what will happen to my software? I think that for a 4G RAM, it will be crashed??
                  on your system memory is not increased by clicking on the tool button?

                  M Christian EhrlicherC 2 Replies Last reply
                  0
                  • stackprogramerS stackprogramer

                    @Christian-Ehrlicher said in WI see memory leakage when a trigger a signal and empty slot is executed in qt?:

                    valgrind

                    So after some time that I use my program after 10000 clicks.... what will happen to my software? I think that for a 4G RAM, it will be crashed??
                    on your system memory is not increased by clicking on the tool button?

                    M Offline
                    M Offline
                    mpergand
                    wrote on last edited by mpergand
                    #9

                    @stackprogramer said in WI see memory leakage when a trigger a signal and empty slot is executed in qt?:

                    So after some time that I use my program after 10000 clicks.... what will happen

                    Have a try with this:

                    #include "mainwindow.h"
                    #include "ui_mainwindow.h"
                    #include <QTimer>
                    
                    
                     string selectedFilePath;
                     string selectedFileName;
                    
                    QFileDialog* fileNameDialog;
                    
                    
                    MainWindow::MainWindow(QWidget *parent)
                        : QMainWindow(parent)
                        , ui(new Ui::MainWindow)
                    {
                        ui->setupUi(this);
                        fileNameDialog=new QFileDialog;
                    
                        auto loopTimer=new QTimer;
                        loopTimer->start(1000);
                    
                        connect(loopTimer,&QTimer::timeout,this,[this]()
                        {
                            QTimer::singleShot(500,this,[]() {
                    
                                fileNameDialog->close();
                            });
                    
                             ui->toolButton->click();
                        });
                    
                    }
                    
                    MainWindow::~MainWindow()
                    {
                        delete ui;
                    }
                    
                    void MainWindow::on_toolButton_clicked()
                    {
                        fileNameDialog->setFileMode(QFileDialog::AnyFile);
                    //    QString fileName = fileNameDialog->getOpenFileName(
                    //        this, tr("Open File"), QDir::currentPath(), tr("Format (*.html *.iq  *.txt *.h)"));
                    //    ui->lineEditFileSelected->setText(fileName);
                        fileNameDialog->open();
                    
                        selectedFilePath = ui->lineEditFileSelected->text().toStdString();
                        selectedFileName = selectedFilePath;
                    }
                    

                    On KDE mem usage stabilizes around 38Mb.

                    stackprogramerS 1 Reply Last reply
                    0
                    • stackprogramerS stackprogramer

                      @Christian-Ehrlicher said in WI see memory leakage when a trigger a signal and empty slot is executed in qt?:

                      valgrind

                      So after some time that I use my program after 10000 clicks.... what will happen to my software? I think that for a 4G RAM, it will be crashed??
                      on your system memory is not increased by clicking on the tool button?

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @stackprogramer said in WI see memory leakage when a trigger a signal and empty slot is executed in qt?:

                      So after some time that I use my program after 10000 clicks.... what will happen to my software? I think that for a 4G RAM, it will be crashed??

                      Since there is no memleak in your example code it will not crash due to out of memory problems.

                      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
                      • M mpergand

                        @stackprogramer said in WI see memory leakage when a trigger a signal and empty slot is executed in qt?:

                        So after some time that I use my program after 10000 clicks.... what will happen

                        Have a try with this:

                        #include "mainwindow.h"
                        #include "ui_mainwindow.h"
                        #include <QTimer>
                        
                        
                         string selectedFilePath;
                         string selectedFileName;
                        
                        QFileDialog* fileNameDialog;
                        
                        
                        MainWindow::MainWindow(QWidget *parent)
                            : QMainWindow(parent)
                            , ui(new Ui::MainWindow)
                        {
                            ui->setupUi(this);
                            fileNameDialog=new QFileDialog;
                        
                            auto loopTimer=new QTimer;
                            loopTimer->start(1000);
                        
                            connect(loopTimer,&QTimer::timeout,this,[this]()
                            {
                                QTimer::singleShot(500,this,[]() {
                        
                                    fileNameDialog->close();
                                });
                        
                                 ui->toolButton->click();
                            });
                        
                        }
                        
                        MainWindow::~MainWindow()
                        {
                            delete ui;
                        }
                        
                        void MainWindow::on_toolButton_clicked()
                        {
                            fileNameDialog->setFileMode(QFileDialog::AnyFile);
                        //    QString fileName = fileNameDialog->getOpenFileName(
                        //        this, tr("Open File"), QDir::currentPath(), tr("Format (*.html *.iq  *.txt *.h)"));
                        //    ui->lineEditFileSelected->setText(fileName);
                            fileNameDialog->open();
                        
                            selectedFilePath = ui->lineEditFileSelected->text().toStdString();
                            selectedFileName = selectedFilePath;
                        }
                        

                        On KDE mem usage stabilizes around 38Mb.

                        stackprogramerS Offline
                        stackprogramerS Offline
                        stackprogramer
                        wrote on last edited by
                        #11

                        @mpergand But I can not comment on the getOpenFileName, It is not solving the problem...

                        @Christian-Ehrlicher Thanks very much. According to your talking so I concluded operating system should manage and free up the memory...

                        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