I'm using Instruments (on Mac) to track memory leaks in a QT app I wrote. I've gotten rid of the ones due to my code and am left with those it is not clear are really leaks and are from QT.
1. QMessageBox - is it destroyed on close?
2. QDrag - is it destroyed when the drag is complete?
An example of the code that registers as a leak is:
void about() {
QMessageBox::information(this,
"About X",
"X is a program.\n") }
void about() {
QMessageBox::information(this, "About X", "X is a program.\n")
}
To copy to clipboard, switch view to plain text mode
and,
void PhotoMailer
::mousePressEvent(QMouseEvent *event
) { //http://doc.trolltech.com/4.2/dnd.html
if (event->button() == Qt::LeftButton) {
mimeData->setUrls(url);
drag->setMimeData(mimeData);
drag->start();
}
}
void PhotoMailer::mousePressEvent(QMouseEvent *event) {
//http://doc.trolltech.com/4.2/dnd.html
if (event->button() == Qt::LeftButton) {
QDrag *drag = new QDrag((QWidget*)this);
QMimeData *mimeData = new QMimeData;
mimeData->setUrls(url);
drag->setMimeData(mimeData);
drag->start();
}
}
To copy to clipboard, switch view to plain text mode
My question is, should I worry - they are created with new and then 'lost', i.e. the calling function returns without telling anyone of the pointer, so I understand that a profiler will flag this as a leak, but will QT take care of them? Or have I missed a programming paradigm here.
Thanks!
-K
Bookmarks