Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Dynamically release memory about QWebView Error
Forum Updated to NodeBB v4.3 + New Features

Dynamically release memory about QWebView Error

Scheduled Pinned Locked Moved Qt WebKit
2 Posts 1 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yangyunfeizj34
    wrote on last edited by
    #1

    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();
    }
    @

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      yangyunfeizj34
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved