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. C++ and QtScript, overload a function
Forum Update on Monday, May 27th 2025

C++ and QtScript, overload a function

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.2k Views
  • 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.
  • D Offline
    D Offline
    Dlang123
    wrote on last edited by
    #1

    Going to start this out with saying, I am not sure if this can be done or not, so I'm asking here. Using QT 4.6.3 and the qtscriptbindings from the labs.

    I create a C++ class (TestClass) with a function doSomething()

    I pass the C++ into the QscriptEngine as "myObject" like so
    @var test = new TestClass();
    QScriptValue objectValue = engine->newQObject(test);
    engine->globalObject().setProperty("myObject", objectValue);@

    Now what I want to do is in the QtScript overload that function doSomething(). Is this possible?

    i.e.
    @myObject.prototype.doSomething = function(){
    print("yeah it works");
    }@

    Something along those lines. That way if a signal was connected in the C++ to the C++ slot, I could either override it or add to it.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      I'm not sure, but I think, it don't work, because IMHO when you create global object you get follow hierarchal structure:

      @
      myObject = function() {
      ...
      this.doSomething = function() {
      // Some commands from C++
      }
      }

      myObject.prototype.doSomething = function(){
      print("yeah it works");
      }
      @

      i.e. direct object method overlap prototype method.
      But I recommend you test it.

      --
      Vasiliy

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dlang123
        wrote on last edited by
        #3

        Yeah I tried it the way I had posted and I get the whole.
        myObject.prototype' [undefined] is not an object

        If I try it with the
        @myObject.proto.doSomething = function(){
        print("yeah it works");
        }@

        Then I don't get the same error, script takes it, but I'm still not 100% clear on the usage of proto and it doesn't work for what I am trying to do.

        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