2010-11-04 15:21:10     QScrollArea Memory Leak

Document created by Aaronwu Employee on Aug 23, 2013
Version 1Show Document
  • View in full screen mode

2010-11-04 15:21:10     QScrollArea Memory Leak

Daniel Tripp (UNITED STATES)

Message: 95570   

 

I'm currently running into a rendering memory leak with QScrollArea (part of QtE 4.5.1). When rendering a QLabel inside of a QScrollArea that extends the boundary of the QScrollArea, a memory leak is found. I cannot replicate this with QtE built for by workstation (testing with QVFB). QLabels containing QPixmap do not recreate this issue.

 

#ifndef MYWIDGET_H

 

#define MYWIDGET_H

 

 

 

#include <QWidget>

 

 

 

class QVBoxLayout;

 

class QScrollArea;

 

class QLabel;

 

class QPushButton;

 

 

 

class MyWidget : public QWidget

 

{

 

    Q_OBJECT

 

 

 

public:

 

    MyWidget(QWidget *parent = 0);

 

 

 

private:

 

    void buildWidget();

 

    void retranslateWidget();

 

 

 

    QVBoxLayout *layout;

 

    QScrollArea *scroll;

 

    QLabel *text;

 

    QPushButton *button;

 

 

 

private slots:

 

    void rebuildScrollArea();

 

};

 

 

 

#endif // MYWIDGET_H

 

 

 

#include "mywidget.h"

 

 

 

#include <QScrollArea>

 

#include <QVBoxLayout>

 

#include <QLabel>

 

#include <QPushButton>

 

#include <QApplication>

 

#include <QImage>

 

 

 

MyWidget::MyWidget(QWidget *parent) : QWidget(parent)

 

{

 

    scroll = NULL;

 

 

 

    setFixedHeight(240);

 

    setFixedWidth(320);

 

 

 

    buildWidget();

 

 

 

    connect(button, SIGNAL(clicked()), this, SLOT(rebuildScrollArea()));

 

}

 

 

 

void MyWidget::buildWidget()

 

{

 

    layout = new QVBoxLayout;

 

    setLayout(layout);

 

 

 

    button = new QPushButton;

 

    layout->addWidget(button);

 

 

 

    rebuildScrollArea();

 

}

 

 

 

void MyWidget::rebuildScrollArea()

 

{

 

    if (scroll) scroll->deleteLater();

 

 

 

    scroll = new QScrollArea;

 

    scroll->setWidgetResizable(true);

 

    //scroll->hide();

 

 

 

    text = new QLabel;

 

    text->setWordWrap(true);

 

    //text->setPixmap(QPixmap(":/stewart.png"));

 

    //text->adjustSize();

 

 

 

    scroll->setWidget(text);

 

 

 

    layout->addWidget(scroll);

 

 

 

    retranslateWidget();

 

}

 

 

 

void MyWidget::retranslateWidget()

 

{

 

    button->setText(tr("Click to Rebuild"));

 

    text->setText(tr("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

 

                     "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

 

                     "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."));

 

 

 

}

 

#include <QtGui/QApplication>

 

#include "mywidget.h"

 

#include "zdefaultstyle.h"

 

 

 

int main(int argc, char *argv[])

 

{

 

    QApplication a(argc, argv);

 

    MyWidget w;

 

 

 

#if defined(Q_WS_S60)

 

    w.showMaximized();

 

#else

 

    w.show();

 

#endif

 

 

 

    return a.exec();

 

}

 

QuoteReplyEditDelete

 

 

2010-11-05 06:46:57     Re: QScrollArea Memory Leak

Aaron Wu (CHINA)

Message: 95589   

 

Please summit your question on qt.nokia.com

Attachments

    Outcomes