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()";
    };
  • 相关阅读:
    ST表学习笔记
    LCA学习笔记
    $ZOJ 2432 Greatest Common Increasing Subsequence$
    $SP15637 GNYR04H - Mr Youngs Picture Permutations$
    Noip2016换教室
    洛谷4718【模板】Pollard-Rho算法
    CQOI2016 密钥破解
    Poj3696 The Lukiest Number
    Noip2012同余方程
    同余
  • 原文地址:https://www.cnblogs.com/threef/p/3350476.html
Copyright © 2011-2022 走看看