zoukankan      html  css  js  c++  java
  • qml中打开本地html

    main.cpp

    QString tmploc = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
    QDir tmpdir(tmploc + "/my_little_project");

    QDirIterator it(":", QDirIterator::Subdirectories);
    bool isHtml = false;
    while (it.hasNext())
    {
        QString tmpfile;
        tmpfile = it.next();
        isHtml = tmpfile.contains("html",Qt::CaseInsensitive);
        if (QFileInfo(tmpfile).isFile()  && (isHtml)  )
        {
            QFileInfo file = QFileInfo(tmpdir.absolutePath() + tmpfile.right(tmpfile.size()-1));
            file.dir().mkpath("."); // create full path if necessary
            QFile::remove(file.absoluteFilePath()); // remove previous file to make sure we have the latest version
            QFile::copy(tmpfile, file.absoluteFilePath());
            break;
        }
    }
    ctxt->setContextProperty(QStringLiteral("baseUrl"), QFileInfo(tmpdir.absolutePath() + "/index1.html").absoluteFilePath());
    

    web.qml中
    //import QtQuick 2.0
    import QtQuick 2.2
    import QtQuick.Layouts 1.1
    import QtQuick.Controls 1.2 as QuickControls
    import QtWebView 1.0

    Item{
    signal changeUrl(string msg)
    property string webParams
    property alias weburl: mywebview.url
    WebView{
    id:mywebview
    parent.width
    height: parent.height
    // url: baseUrl
    // url:"file:///storage/sdcard0/my_little_project/index1.html"
    url:"file:///"+baseUrl //这里必须这么写,否则有问题
    onUrlChanged: {
    changeUrl(mywebview.url+"")
    webParams = mywebview.url
    console.log("~~~~~~~~~~url:"+baseUrl)
    }
    }

    }

  • 相关阅读:
    windows server 2008 r2 切换windows 7主题方法
    JAVA环境安装
    Oracle 11gR2 安装教学
    webmin-1.810 安装
    Windows Squid 安装配置
    Zyxel Switch-How to block a fake DHCP server without enabling DHCP snooping?
    Java介绍
    cookies和session区别
    牛刀小试之Django二
    小试牛刀之Django
  • 原文地址:https://www.cnblogs.com/xianqingzh/p/4681135.html
Copyright © 2011-2022 走看看