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

    }

  • 相关阅读:
    Oracle And子句
    Oracle Where(条件)子句用法
    extern “C”的作用详解
    函数重载
    给变量起名字的网站。
    同步异步
    CCS5.5安装破解过程
    Semaphore_pend();阻塞函数
    vi常用命令
    Linux下VI操作命令
  • 原文地址:https://www.cnblogs.com/xianqingzh/p/4681135.html
Copyright © 2020-2023  润新知