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()";
    };
  • 相关阅读:
    进程
    并发编程小结
    操作系统发展史
    基于socketsever实现并发的socket编程
    UDP套接字
    粘包问题及解决
    socket套接字编程
    TCP协议与三次握手四次挥手
    OSI七层协议
    互联网的组成
  • 原文地址:https://www.cnblogs.com/threef/p/3350476.html
Copyright © 2011-2022 走看看