[Qt-interest] Qt Memory Leak (or Fragmentation?)

Daniel Tripp tripp.daniel at rocketmail.com
Thu Jul 8 18:09:45 CEST 2010


I'm unable to use valgrind due to this being developed on an embedded system 
(Blackfin w/ uCLinux and no MMU). Is this a fragmentation issue?


----- Original Message ----
From: "william.crocker at analog.com" <william.crocker at analog.com>
Cc: qt-interest at trolltech.com
Sent: Thu, July 8, 2010 11:02:58 AM
Subject: Re: [Qt-interest] Qt Memory Leak (or Fragmentation?)

Daniel:

You need to add a tool like valgrind or purify($) to your belt.

Bill

Daniel Tripp wrote:
> I'm running into a memory issue with Qt. If the text of a QLabel changes, it 
> slowly eats memory. I don't see any apparent leaks with the my test code, but 
> here it is just in case. Does anyone know how to prevent this?
> 
> 
> main.cpp:
> 
> 
> #include "labeltest.h"
> #include <QApplication>
> int main(int argc, char *argv[]) 
> {
>      QApplication a(argc, argv);
>      LabelTest test;
>      test.show();
>      return a.exec();
> } 
> 
> labeltest.cpp:
>  
> #include "labeltest.h"
> #include <QLabel>
> #include <QPushButton>
> #include <QVBoxLayout>
> 
> LabelTest::LabelTest(QWidget *parent) : QWidget(parent)
> {
>      shortWord = false;
>      layout = new QVBoxLayout(this);
>      randomLabel = new QLabel(this);
>      updateLabel();
>      layout->addWidget(randomLabel);
>      button = new QPushButton(this);
>      button->setText("Click Me");    
>      button->setFocus();
>      layout->addWidget(button);
>       connect(button, SIGNAL(clicked()), this, SLOT(updateLabel()));
> }
> void LabelTest::updateLabel() 
> {
>      if(shortWord)
>          randomLabel->setText("Short string");
>      else
>          randomLabel->setText("This is a considerably longer string");
>      shortWord = !shortWord;
> } 
> 
> labeltest.h:
> 
> #ifndef LABELTEST
> #define LABELTEST
> 
> #include <QWidget>
> #include <QList>
> class QLabel;
> class QPushButton;
> class QVBoxLayout;
> 
> class LabelTest : public QWidget 
> {
>      Q_OBJECT
> public:
>      LabelTest(QWidget *parent = 0);
> private:
>      QLabel *randomLabel;
>      QPushButton *button;
>      QVBoxLayout *layout;
>      bool shortWord;
> private slots:
>      void updateLabel();
> };
> #endif 
> 
> labeltest.pro:
> 
> 
> SOURCES += main.cpp \
>             labeltest.cpp
> HEADERS += labeltest.h
> 
> 
>      
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest



      




More information about the Qt-interest-old mailing list