how to load html,css and JS file for webView from qrc on android



  • I have a small website which I made for MicroProject for college . Now I just want to give for Android MicroProject cause I am lazy. So I have used WebView and it worked on Desktop . But When I compile it for android I get

    0_1538584775013_Screenshot_20181003-215610.jpg

    here is the code :-

    main.qml:-

    import QtQuick 2.11
    import QtQuick.Window 2.11
    import QtWebView 1.1
    
    Window {
    		id: window
    		visible: true
    		width: 640
    		height: 480
    		title: qsTr("Stack")
    
    		WebView{
    				id:webView
    				anchors.fill:parent
    				objectName: "webView"
    		}
    }
    

    main.cpp:-

    #include <QApplication>
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    #include  <QtWebView/QtWebView>
    
    
    int main(int argc, char *argv[])
    {
    		QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
    		QApplication app(argc, argv);
    		QtWebView::initialize();
    
    		QQmlApplicationEngine engine;
    		engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
    		qDebug() << "engine:- ";
    		QObject *root = engine.rootObjects().front()->findChild<QObject*>("webView");
    		qDebug() << root ;
    		root->setProperty("url",QUrl("qrc:/EditorsWar/index.html"));
    		if (engine.rootObjects().isEmpty())
    				return -1;
    
    
    		return app.exec();
    }
    

    I don't understand why this is not working on android but works on Desktop (ArchLinux/KDE)


  • Qt Champions 2018

    @noone You will need to extract the content from qrc file to some location writable by your application and then load it from there in webview.



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