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
QtWS25 Last Chance

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.
  • nooneN Offline
    nooneN Offline
    noone
    wrote on 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)

    jsulmJ 1 Reply Last reply
    0
    • nooneN noone

      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)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

      • Login

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