[Qt-interest] Will it cause a memory leak?

Kermit Mei kermit.mei at gmail.com
Thu Jul 9 12:44:36 CEST 2009


Hello community!

I want to pass an event to another widget, but I doubt the following
code would cause a memory leak:

void HtmlEditor::fileNew()
{
    if (maybeSave()) {
        ui->webView->setHtml("<p></p>");
        ui->webView->setFocus();
        ui->webView->page()->setContentEditable(true);
        setCurrentFileName(QString());
        setWindowModified(false);

        // quirk in QWebView: need an initial mouse click to show the cursor

        int mx = ui->webView->width() / 2;

        int my = ui->webView->height() / 2;

        QPoint center = QPoint(mx, my);

        QMouseEvent *e1 = new QMouseEvent(QEvent::MouseButtonPress, center,
                                          Qt::LeftButton, Qt::LeftButton,
                                          Qt::NoModifier);
 
        QMouseEvent *e2 = new QMouseEvent(QEvent::MouseButtonRelease, center,
                                          Qt::LeftButton, Qt::LeftButton,
                                          Qt::NoModifier);
        QApplication::postEvent(ui->webView, e1);

        QApplication::postEvent(ui->webView, e2);
    }
}


The tow QMouseEvent haven't been delete in anywhere. If it is really a
memory leak, then where can I delete them? 

Thanks.
Kermit




More information about the Qt-interest-old mailing list