Dynamically release memory about QWebView Error



  • Hello,
    I've been using Qt 4.7.4 for a while and I get a problem: I released memory dynamically,after a few times, the program crashed. I set the QWebView::setAttribute(Qt::WA_DeleteOnCLose);

    The first time free memory,no error happened. but after a few, when QWebView show, the program crashed.
    VS2010 shows error in "TextBreakIterator* setUpIterator()" .

    Someone can help me? Thank you!

    The code is:

    /main.cpp/ /MyDialog.h/ /MyDialog.cpp/ /MyWebView.h/ /MyWebView.cpp/
    @
    #include "MyDialog.h"
    #include <QtGui/QApplication>
    #include <qtextcodec.h>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("gb2312"));
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("gb2312"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("gb2312"));
    MyDialog *w = new MyDialog;
    w->show();
    int ret = a.exec();
    return ret;
    }
    @

    @#ifndef MYDIALOG_H
    #define MYDIALOG_H

    #include <qdialog.h>
    #include <qstring.h>
    #include <qpushbutton.h>
    #include <MyWebView.h>

    class MyDialog : public QDialog
    {
    Q_OBJECT

    public:
    MyDialog(QWidget *parent = 0);
    ~MyDialog();

    QWebView *RetWebView();

    public slots:
    void slotButtonClicked();
    void slotBrowserClose();

    private:
    QString loginUrl;
    QString logoutUrl;
    MyWebView *browser;
    QPushButton *dispatchButton;
    };

    #endif // MYDIALOG_H
    @

    @
    #include "MyDialog.h"

    MyDialog::MyDialog(QWidget *parent)
    : QDialog(parent)
    {
    dispatchButton = NULL;
    dispatchButton = new QPushButton(tr("dispath"),this);
    browser = NULL;
    connect(dispatchButton,
    SIGNAL(clicked()),
    this,
    SLOT(slotButtonClicked()));
    }

    MyDialog::~MyDialog()
    {
    if(browser != NULL)
    {
    delete browser;
    }
    }

    void MyDialog::slotButtonClicked()
    {
    if(browser == NULL)
    {
    browser = new MyWebView;
    browser->setAttribute(Qt::WA_DeleteOnClose);
    browser->load(QUrl("http://www.yahoo.com"));
    browser->show();
    connect(browser,
    SIGNAL(signalViewClosed()),
    this,
    SLOT(slotBrowserClose()));
    }
    }

    void MyDialog::slotBrowserClose()
    {
    browser = NULL;
    }

    QWebView *MyDialog::RetWebView()
    {
    return browser;
    }
    @

    @
    #ifndef MYWEBVIEW_H
    #define MYWEBVIEW_H

    #include <QWebView>
    #include <qwidget.h>
    #include <qevent.h>

    class MyWebView : public QWebView
    {
    Q_OBJECT

    public:
    MyWebView(QWidget *parent = 0);
    virtual~MyWebView();

    protected slots:
    void closeEvent ( QCloseEvent * event );

    signals:
    void signalViewClosed();
    private:

    };

    #endif // MYWEBVIEW_H
    @

    @
    #include "MyWebView.h"

    MyWebView::MyWebView(QWidget *parent)
    : QWebView(parent)
    {

    }

    MyWebView::~MyWebView()
    {
    int j = 0;
    }

    void MyWebView::closeEvent ( QCloseEvent * event )
    {
    emit signalViewClosed();
    event->accept();
    }
    @



  • I load a new Version Qt 4.8.0,and rebuild this program, the bug disappear miraculous.
    Maybe this is a bug in Qt 4.7.4.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.