QPixmap에서 QPainter를 사용하여 메모리 누수 문제가 있습니다. 지구상에서 약 250000 포인트를지도 (항법 점)에 설정해야합니다. 각각은 동일한 아이콘을 공유하지만 특정 레이블이 있습니다. 이 모든 점들을 같은 레이어에 추가합니다.Qpainter 메모리 누수 피하기
void Gspv::addFixes() // waypoints layer
{
waypoints = new GeometryLayer("Waypoints", mapadapter);
mc->addLayer(waypoints);
//Icon
QPixmap icone(38,38);
icone.fill(Qt::transparent);
QPainter *paint = new QPainter(&icone);
paint->setRenderHint(QPainter::Antialiasing);
paint->setBrush(Qt::cyan);
paint->setPen(Qt::black);
static const QPoint triangle[3] = {
QPoint(15,0),
QPoint(3, 20),
QPoint(27,20)
};
paint->drawPolygon(triangle, 3);
delete paint;
//Check file
QFile file(QCoreApplication::applicationDirPath() + "/data/Waypoints.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::information(0, "erreur lecture fichier : " + file.fileName(), file.errorString());
return;
}
//Parsing file
QTextStream in(&file);
while(!in.atEnd()) {
QString line = in.readLine();
QStringList fields = line.split(",");
QString str = fields.at(1);
double latitude = str.toDouble();
str = fields.at(2);
double longitude = str.toDouble();
str = fields.at(0);
addCode(icone,str); // Prob here
//Add current point to layer
Point* pointCourant = new Point(longitude, latitude, icone, str);
pointCourant->setBaselevel(10);
pointCourant->setMaxsize(QSize(38, 38));
waypoints->addGeometry(pointCourant);
}
file.close();
}
//Add code to QPixmap
void Gspv::addCode(QPixmap &pm, QString &code)
{
QPainter pmp(&pm);
pmp.setPen(Qt::black);
pmp.setFont(QFont("ArialBold",9));
pmp.eraseRect(0,20,38,15);
pmp.drawText(0,32,code);
}
모두가 심각한 메모리 누수가 발생하는 것을 제외하고 예상대로 작동합니다
여기 내 코드입니다. while 루프 내에 코드를 추가 할 때 문제가 발생합니다. 내가 무엇을 하든지 (addcode 메소드에있는 addcode 또는 addCode와 같은 특정 코드에있는 addcode), 나는 메모리 누수가 발생한다.
코드 만 감소된다하더라도 :
는void Gspv::addCode(QPixmap &pm, QString &code)
{
QPainter pmp(&pm);
// here it does nothing !
}
메모리 누수이다. 그리고 그 문장이 정적인지 동적인지 상관없이, 결과는 같습니다.
코드를 추가하지 않으면 메모리 사용량이 약 152Mo로 충분합니다. 이 간단한 코드를 추가하면 메모리 부족으로 버그가 발생합니다.
QPainter 및 메모리 누수에 대한 많은 게시물을 읽었지만 처리 할 수 없습니다.
도움이 필요하십니까?
미리 감사드립니다.
QPixmap 대신 QImage를 사용하십시오. – eyllanesc
보기 : https://stackoverflow.com/questions/10307860/what-is-the-difference-between-qimage-and-qpixmap – eyllanesc
화가가 누수의 근원이 확실합니까? 제작자가 가장 최근의 코드를 작성하고 실행 했습니까? 그것은 종종 붙어 있습니다 ... – dtech