zoukankan      html  css  js  c++  java
  • qt,script

    qt 与 js 交互:

    QFile file("./s.js");
        if (!file.open(QIODevice::ReadOnly))
        {
            qDebug() << "open error!";
            exit(0);
        }
        QTextStream in(&file);
    
        in.setCodec("UTF-8");
        QString str = in.readAll();
        qDebug() << qApp->applicationDirPath();
        qDebug() << str;
        file.close();
    
        QScriptEngine e;
        QScriptValue v = e.evaluate(str);
        if (e.hasUncaughtException())
        {
            qDebug() << "error!" << endl;
        }
    
        QScriptValue global = e.globalObject();
    
        QScriptValue obj = global.property("obj");
        qDebug() << obj.property("txt").toString();
    
        QScriptValue h = e.newQObject(new Holder);// Holder 为QObject,动态属性 供 脚本引擎访问
        qDebug() << "before s obj:" << h.property("str").toString();
        obj.setProperty("holder", h);
    
    
        qDebug() << h.property("str").toString();
        obj.property("run").call(obj);
        qDebug() << obj.property("txt").toString();
        qDebug() << h.property("str").toString();
    var obj = Object;
    obj.txt = "action1";
    obj.run = function()
    {
        this.txt = "chang this.txt";
        this.holder.str = "this.holder.text.toUpperCase()";
    };
  • 相关阅读:
    async/await
    js继承
    js处理上下文代码的2个阶段
    js相关地址
    vue自定义指令钩子函数
    vue 组件
    vue methods和computed,v-show和v-if
    vue 生命周期
    DOM操作——怎样添加、移除、移动、复制、创建和查找节点
    js 传递参数
  • 原文地址:https://www.cnblogs.com/threef/p/3350476.html
Copyright © 2011-2022 走看看