Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Possible to override toString in Javascript for a QObject-derived class?
Forum Updated to NodeBB v4.3 + New Features

Possible to override toString in Javascript for a QObject-derived class?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.5k 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.
  • M Offline
    M Offline
    mjmvisser
    wrote on 5 Nov 2012, 22:54 last edited by
    #1

    I've exposed a property from C++ called "paths". Currently, this property returns a const QStringList, which is nicely mapped to a Javascript array of strings. I now need "paths" to support sequences of frames, so each "path" now has additional metadata (the frame list), which may also involve QObject-derived classes. I'd like this new object to still behave like a string, but expose additional properties.

    For example, a sequence of 4 frames:
    @["/foo/bar.0001.exr",
    "/foo/bar.0002.exr",
    "/foo/bar.0003.exr",
    "/foo/bar.0004.exr"]@

    could be represented as an Object with a "toString()" method that returns
    @"/foo/bar.d.exr"@

    and a "frameList" property that returns
    @[1,2,3,4]@

    I've tried adding this to the class:

    @ Q_INVOKABLE const QString toString() const;@

    But it has no effect. :-(

    So, currently possible? Good Idea/Bad Idea?

    I should mention that I'm somewhat familiar with the qtdeclarative module, so I'd be willing to take a stab at adding this feature myself if given a bit of direction on how to proceed (and if it's not a Bad Idea). I'm using Qt5 from github.

    cheers,
    -Mark

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on 14 Nov 2012, 01:46 last edited by
      #2

      Hi,

      Check out the qv8qobjectwrapper.cpp:
      static v8::Handlev8::Value ToString(QV8Engine *engine, QObject *object, int, v8::Handlev8::Object)

      You can modify that to call the toString() function of object if it exists (eg, via QMetaObject::invokeMethod() after first doing a QMetaObject::property() lookup and determining if it's a function).

      Cheers,
      Chris.

      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