Qt 调用JS脚本中的函数

QString MainWindow::doJS(QString m_password, QString m_vCode, QString verifycodeHex)
{
    QString m_encodePassword = "";
 
 
        QFile _scriptFile(":/res/QQ.js");
        if (!_scriptFile.open(QIODevice::ReadOnly))
        {
            m_encodePassword.clear();
            qWarning() << "encodePass.js open failed";
            return NULL;
        }
        QTextStream _stream(&_scriptFile);
        QString _contents = _stream.readAll();
        _scriptFile.close();
        QScriptEngine _engine;
        QScriptValue _js = _engine.evaluate(_contents);
        QScriptValue _passwordEncoding = _engine.globalObject().property("func");
        QScriptValueList _args;
        _args << QScriptValue(m_password) << QScriptValue(m_vCode.toUpper()) << QScriptValue(verifycodeHex);
        m_encodePassword = _passwordEncoding.call(QScriptValue(), _args).toString();
        return m_encodePassword;
}

你可能感兴趣的:(Qt 调用JS脚本中的函数)