QML android webview error



  • Hello,

    I m trying to display some local html / css file but I get an "ERR_UNKNOWN_URL_SCHEME

    I use this to import the html css file on my .pro

    deployment.files += test.html
    deployment.files += test.css
    deployment.path = /assets
    INSTALLS += deployment
    

    my c++ file :

    QFile file( "assets:/test.html" );
    
          if( !file.exists() )
          {
            qDebug() << "---------The file" << file.fileName() << "does not exist.-----------------";
          }
          else qDebug() << "---------The file" << file.fileName() << "exist.-----------------";
    
          engine.rootContext()->setContextProperty("pathToFile", "assets:/test.html");
    

    my .qml file :

    WebView {
    
                    id: webview
                    url: pathToFile
                    anchors.fill: parent
                }
    

    I know that the files exists, but I dont know why it didnt work .... thanks for your help



  • Hi! Your file path in QFile(...) is correct but when you need an URL for an asset on Android then you have to use file:///android_asset/.... So, assuming your test file is assets:/data/test.html, the correct URL is:

    WebView {
      url: "file:///android_asset/data/test.html"
    }
    

Log in to reply
 

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