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


-
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; } }


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

Gradually used memory volume is increased... even for 100 times... and ...so on
-
There is no One that can help me for understanding this strange problem?
-
Provide a minimal, compilable example - your code snippet does not cause a leak.
-
@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.
You can dowload it from below link
https://www.mediafire.com/file/ji6o7npfvjgwyyi/Qt-Test.zip/file -
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.
-
@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-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?@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.
-
@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?@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.
-
@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.
@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...