Can't access public slots from QtScript



  • EDIT: For some reason, the forum pust a "[removed]" instead of my class name. The class name is just JavaScript

    Hey there, I have this class:

    @class [removed] public QObject {
    Q_OBJECT
    public:
    JavaScript();
    bool executeFromFile(QString file);
    bool enabled;

    public slots:
        void setEnabled( bool enabled );
        bool isEnabled() const;    
    
    private:
        QScriptEngine engine;
    

    };@

    And definitions here:

    @[removed]:JavaScript() {
    executeFromFile("test.js");
    }
    bool [removed]:executeFromFile(QString file) {
    QFile scriptFile(file);
    if (!scriptFile.open(QIODevice::ReadOnly)) return false;
    QTextStream stream(&scriptFile);
    QString contents = stream.readAll();
    scriptFile.close();
    engine.evaluate(contents, file);
    return true;
    }

    void [removed]:setEnabled( bool enabled ) {
    [removed]:enabled = enabled;
    }
    bool [removed]:isEnabled() const {
    return enabled;
    }@

    I'm trying to access the public slots previously defined in the header file like the documentation says:

    http://doc.qt.digia.com/qt/scripting.html#making-a-c-object-available-to-scripts-written-in-qtscript

    The test.js file looks like this, just like the examples of the docs:

    @var obj = new JavaScript;
    obj.setEnabled( true );
    print( "obj is enabled: " + obj.isEnabled() );@

    But i'm not getting anything. It seems it doesn't find the JavaScript object. What am I missing?

    Doin a simple @print(1+1)@ works just fine.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.