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)
    }
    }

    }

  • 相关阅读:
    [转]java中的匿名内部类总结
    linux 命令总结
    [转载]nohub java -jar xx.jar >/dev/null 2>&1 &
    Java正则表达式Pattern和Matcher类详解
    spark基础知识介绍(包含foreachPartition写入mysql)
    spark 运行架构
    spark核心原理
    行动操作
    控制操作
    键值转换操作
  • 原文地址:https://www.cnblogs.com/xianqingzh/p/4681135.html
Copyright © 2011-2022 走看看