PDA

View Full Version : QGraphicsTextItem setPlainText Memory issue



decin
9th March 2010, 07:46
Hi,
I am using QGraphicsTextItem to display a text that is continiously being updated at a given time interval. i am calling the setPlainText to set the text. It is observed on each call to setPlainText the memory used by the application keeps increasing.

Below is a sample code where this issue can be noticed. you can notice the memory used by the application in windows task manager.


#include <QtGui/QApplication>
#include <QGraphicsView>
#include <QGraphicsTextItem>
#include <QTimer>
#include <limits>


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsTextItem pItem ;
pItem.setPlainText("This is a text");
scene.addItem(&pItem);
view.show();
QString strText("text");
double i = 0;
while(i<std::numeric_limits<int>::max())
{
pItem.setPlainText(strText + QString::number(i));
QApplication::processEvents();
i++;
}
scene.removeItem(&pItem);
return a.exec();
}



I am using Qt 4.6.2 on windows vista
visual studio 2008.

tia,

decin
10th March 2010, 01:54
http://bugreports.qt.nokia.com/browse/QTBUG-8862

arpspatel
10th March 2010, 03:03
why are you using QGraphicsView/Scene/TextItem ?? or is this just a small part of some other project?? wouldnt QLabel be faster and easier to implement..