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. QScriptEngine and QMetaObject
Qt 6.11 is out! See what's new in the release blog

QScriptEngine and QMetaObject

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 757 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.
  • K Offline
    K Offline
    kovand11
    wrote on last edited by
    #1

    I am working based on the documentation of QScriptEngine with QMetaObject.
    I made my own class, inherited from QObject. It seems to work, but I have some problems.

    @ QScriptValue mySpecialQObjectConstructor(QScriptContext *context,
    QScriptEngine *engine)
    {
    QObject *parent = context->argument(0).toQObject();
    QObject *object = new QObject(parent);
    return engine->newQObject(object, QScriptEngine::ScriptOwnership);
    }

    ...

    QScriptValue ctor = engine.newFunction(mySpecialQObjectConstructor);
    QScriptValue metaObject = engine.newQMetaObject(&QObject::staticMetaObject, ctor);
    engine.globalObject().setProperty("QObject", metaObject);

    QScriptValue result = engine.evaluate("new QObject()");@

    Firstly, I can call the slots, but not the normal functions, from the script side. Why is that?
    If I give return value to my slots it seems to work, Is it a good practice?

    http://www.qtcentre.org/threads/59771-How-to-really-really-use-custom-QtScript-classes

    Looking at the last post, he uses signals and slots:

    @x.mySignal.connect(y.mySlot);@

    What can be at the place of y.mySlot? Surely I can use an another registered QMetaObject. But can I use registered standalone functions? Or script side functions?

    Thanks in advance.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      No it's not, don't give a return value to a slot.

      However, you can use Q_INVOKABLE for your purpose.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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