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. Bind class to QJSEngine not being QObject
Qt 6.11 is out! See what's new in the release blog

Bind class to QJSEngine not being QObject

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 2 Posters 860 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
    JAPA
    wrote on last edited by
    #1

    Hello,

    I would like to expose some classes (more than 200) to QJSEngine. I don't want to inherit from QObject in my classes, so that discards Q_INVOKABLE or slots options. Just a normal binding like LUA or V8JS would do.
    Is there any way to do this?

    Regards

    JAPA

    J 1 Reply Last reply
    0
    • J JAPA

      Hello,

      I would like to expose some classes (more than 200) to QJSEngine. I don't want to inherit from QObject in my classes, so that discards Q_INVOKABLE or slots options. Just a normal binding like LUA or V8JS would do.
      Is there any way to do this?

      Regards

      JAPA

      J Offline
      J Offline
      JAPA
      wrote on last edited by
      #2

      @JAPA
      When I say I dont want, in fact it is I can't. I cannot inherit my class from QObject for two reasons (1. many many classes, 2, Some of them are used in lists and they are instanced millions of times, so that would increase the memory footprint),

      fcarneyF 1 Reply Last reply
      0
      • J JAPA

        @JAPA
        When I say I dont want, in fact it is I can't. I cannot inherit my class from QObject for two reasons (1. many many classes, 2, Some of them are used in lists and they are instanced millions of times, so that would increase the memory footprint),

        fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        @JAPA Are you going to have these millions of objects inside the engine all at the same time?

        I have run into major speed issues doing Javascript calculations for just 4000 objects. I had to create specific C++ functions to manipulate data in C++ as the JS was too slow.

        If you are going to window (expose a few at a time using a model) then you can expose information about the objects to QML/JS a bit at a time. Even a temporary QObject that references the object/objects you want to manipulate in the engine. I cannot imagine it will be performant at all to inject millions of objects into the js engine at the same time.

        C++ is a perfectly valid school of magic.

        J 1 Reply Last reply
        0
        • fcarneyF fcarney

          @JAPA Are you going to have these millions of objects inside the engine all at the same time?

          I have run into major speed issues doing Javascript calculations for just 4000 objects. I had to create specific C++ functions to manipulate data in C++ as the JS was too slow.

          If you are going to window (expose a few at a time using a model) then you can expose information about the objects to QML/JS a bit at a time. Even a temporary QObject that references the object/objects you want to manipulate in the engine. I cannot imagine it will be performant at all to inject millions of objects into the js engine at the same time.

          J Offline
          J Offline
          JAPA
          wrote on last edited by
          #4

          @fcarney
          Hello, Thanks for answering.

          No, I am not going to have that amount into the JS engine at the same time, but i can send any of these objects to the engine at any time.

          My current solution is to serialize (into JSON) the one I want to send to the JS engine and then deserialized inside the engine which is slow the traffic is high.

          That forces me to have two implementations of the same class. One for C++ and one for JS. I don't use the objects as simple storage. They have functionality so I need methods.

          I don't get the idea of the temporary object. How would you do it? Ant the end of the day I would need to access the methods in my C++ class, and I don't down how the temporary QObject would access those methods.

          Thanks!

          fcarneyF 1 Reply Last reply
          0
          • J JAPA

            @fcarney
            Hello, Thanks for answering.

            No, I am not going to have that amount into the JS engine at the same time, but i can send any of these objects to the engine at any time.

            My current solution is to serialize (into JSON) the one I want to send to the JS engine and then deserialized inside the engine which is slow the traffic is high.

            That forces me to have two implementations of the same class. One for C++ and one for JS. I don't use the objects as simple storage. They have functionality so I need methods.

            I don't get the idea of the temporary object. How would you do it? Ant the end of the day I would need to access the methods in my C++ class, and I don't down how the temporary QObject would access those methods.

            Thanks!

            fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            @JAPA I would probably use a model and expose the objects you are currently manipulating. Look up qt model/view concepts. With a model one interface object can expose a whole set.

            It will most likely require a bit of work to expose what you want to the js engine.

            C++ is a perfectly valid school of magic.

            J 1 Reply Last reply
            0
            • fcarneyF fcarney

              @JAPA I would probably use a model and expose the objects you are currently manipulating. Look up qt model/view concepts. With a model one interface object can expose a whole set.

              It will most likely require a bit of work to expose what you want to the js engine.

              J Offline
              J Offline
              JAPA
              wrote on last edited by
              #6

              @fcarney said in Bind class to QJSEngine not being QObject:

              model/view

              Do you mean one model per object?

              fcarneyF 1 Reply Last reply
              0
              • J JAPA

                @fcarney said in Bind class to QJSEngine not being QObject:

                model/view

                Do you mean one model per object?

                fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #7

                @JAPA I don't know what your objects look like. But if you want to bring in 200 classes then it could be one model per object. Unless it makes sense to combine them.

                C++ is a perfectly valid school of magic.

                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