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 {
    bool executeFromFile(QString file);
    bool enabled;

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


    And definitions here:

    @[removed]:JavaScript() {
    bool [removed]:executeFromFile(QString file) {
    QFile scriptFile(file);
    if (! return false;
    QTextStream stream(&scriptFile);
    QString contents = stream.readAll();
    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:

    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.