You are not logged in.

1

Monday, March 8th 2010, 10:59pm

Memory leak in QFileDialog

Hi everybody,

I am new to Qt. I am writing a GUI application for data analysis and data viewing. Using some examples I have constructed a simple GUI where the button "Open" opens a file dialogue and writes the file path to the object "lineEdit".

One thing I noticed that when I run this program and keep pushing button "Open" and choosing different files after about every 5 openings this program takes additional 0.1Mb of my RAM. It means I never can go back to the amount of the memory program was using at the beginning. This is quiet alot if I need to run program for a long time and analyse loads of data.

I am using:

Qt creator 1.2.1
Based on Qt 4.5.3 (64 bit)

under Fedora11.

Could anybody tell me whether I am doing something wrong?

Thank you

Please find below h and cpp files structure


////header file

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include "ui_mainwindow.h"

namespace Ui
{
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();

public slots:
void getPath();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H


/////cpp file

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QtGui>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->actionOpen, SIGNAL( triggered() ), this, SLOT( getPath() ) );
connect( ui->pushButton_Open, SIGNAL( clicked() ), this, SLOT( getPath() ) );

}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::getPath()
{
QString path;

path = QFileDialog::getOpenFileName(
this,
"Choose a file to open",
QString::null,
QString::null);

ui->lineEdit->setText( path );
}

This post has been edited 2 times, last edit by "Ramzes13" (Mar 17th 2010, 9:32pm)


Rate this thread