Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. how to load html,css and JS file for webView from qrc on android

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

Scheduled Pinned Locked Moved Solved Mobile and Embedded
webviewqmlandroidqrc
2 Posts 2 Posters 1.6k Views
  • 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.
  • N Offline
    N Offline
    noone
    wrote on 3 Oct 2018, 16:43 last edited by
    #1

    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)

    J 1 Reply Last reply 4 Oct 2018, 05:59
    0
    • N noone
      3 Oct 2018, 16:43

      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)

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 4 Oct 2018, 05:59 last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      1/2

      3 Oct 2018, 16:43

      • Login

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