Home · Tutorial · Classes · Functions · Language · QSA Workbench · Qt Documentation · www.trolltech.com

Import Script example

The import script examples shows how one can "import" scripts external scripts. This is done by having a QObject with a slot evaluate that can be called from script. In this function we open the requested file and evaluate it in the interpreter that is calling the slot.

The contents of the function is listed below.

    void Tools::evaluate(const QString &scriptFile)
    {
        QFile f(scriptFile);

        if (!f.exists()) {
            m_interpreter->throwError("File '" + scriptFile + "' does not exist");
            return;
        }

        if (!f.open(QFile::Text | QFile::ReadOnly)) {
            m_interpreter->throwError("File '" + scriptFile + "' could not be read");
            return;
        }

        QString code = QString::fromLocal8Bit(f.readAll());
        m_interpreter->evaluate(code, 0, "evaluated(" + scriptFile + ")");

    }


Copyright © 2006 Trolltech Trademarks
QSA 1.2.2