开发者

Constructing / destructing QApplication causes QWebView to mess up rendering of HTML

We need to create & destroy instances of QApplication, as we want to use Qt in a plug-in to an existing host application.

void multiQT()
{
    int argc = 0;
    QApplication app(argc, NULL);

    QWebView view;
    view.setHtml("<html><head><title>Title</title></head><body><h1>Hello World</h1></body></html>");
    view.show();

    app.exec();
}


main(int argc, char** argv)
{
    // First call works fine, QWebView renders the HTML just fine
    multiQT();

    // Second call fails, QWebView strips HTML tags from HTML text and 
    // and renders "TitleHello World"
 multiQT();
}

When showing the QWebView the second time, it does not render the HTML properly. Do we need to do some additional (re-)initializations in QApplication or QW开发者_如何学CebView?


You might have run into something that has been very lightly tested, the QApplication object among others creates/holds some of the rendering context information of widgets, I don't think it was ever planned for people to take it down and put it back up again. There might be some static content that does not get reinitialised correctly when somebody tries what you are trying to do.


You are supposed to have only 1 QApplication object, and only 1 call to exec(). Maybe you should try this.

QWebView * multiQT()
{
    QWebView *view = new QWebView;
    view->setHtml("<html><head><title>Title</title></head><body><h1>Hello World</h1></body></html>");
    view->show();

    return view;
}

main(int argc, char** argv)
{
    QApplication app(argc, NULL);

    QWebView * web0 = multiQT();

    QWebView * web1 = multiQT();

    app.exec();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜