Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't access public slots from QtScript

Can't access public slots from QtScript

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 738 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jviotti
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved