Important: Please read the Qt Code of Conduct -

Webview content becomes empty if set Android targetSdkVersion 29 or 30

  • Testing QT version: QT5.12.4, QT 5.15.3
    Testing codes: QT example webview/minibrowser; my own project.
    Webview displays empty when set targetSdkVersion more than 28. But now Google requires targetSdkVersion 29 (at least).

    Html String (htmlStr): "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "">\n<html><head><meta name="qrichtext" content="1" /><style type="text/css">\np, li { white-space: pre-wrap; }\n</style></head><body style=" font-family:'.AppleSystemUIFont'; font-size:13pt; font-weight:400; font-style:normal;">\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> <span style=" color:#110d62;"> </span><span style=" font-weight:600; color:#110d62;">Welcome to set Android TargetSdkVersion as 29</span></p>\n<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This is webview testing when set targetSdkVersion in QT. When set TargetSdkVersion as 29, if webview load content str has Qt-specific CSS properties like this, webview content display empty. Method is using webViewId.loadHtml(contentStr);</p></body></html>"

    Note: there are "-qt-block-indent", "qrichtext", "-qt-paragraph-" in html strings, if has no these (like following workedHtmlStr), webview works

    workedHtmlStr : "<!DOCTYPE html>\n<html>\n<head>\n<style>\nbody {background-color: powderblue;}\nh1 {color: blue;}\np {color: red;}\n</style>\n</head>\n<body>\n\n<h1>This is a heading</h1>\n<p>This is a paragraph.</p>\n\n</body>\n</html>"

    Function: webViewId.loadHtml(htmlStr);

    Testing results: (left is using 28, right one is using 29);

    Any suggestion or solutions? or how to transfer qrich qt css to standard html str?
    I appreciate any comments or suggestions. Urgent bug for me. Thanks

Log in to reply