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

    }

  • 相关阅读:
    构造注入
    关于事件
    泛型的一些补充
    [转]汇编语言之寄存器使用(bx,si,di,bp)
    asp.net计算页面执行时间
    运行 组件服务器 dcomcnfg
    Craig's Utility Library
    MASM内部数据类型 from: Intel汇编语言程序(第四版).djvu
    Python interpreter clear console screen
    C大小写转换问题
  • 原文地址:https://www.cnblogs.com/xianqingzh/p/4681135.html
Copyright © 2011-2022 走看看