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. Signals passing pointer

Signals passing pointer

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 2.5k 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.
  • M Offline
    M Offline
    mondo
    wrote on last edited by mondo
    #1

    I wish to pass a pointer by singals and slots.

    Connections{
                    target: device
                    onImageBufCreated:{
                        real_time_image.initImageBuf(pFrameBuf)
                    }
                }
    
    

    The device issues a ImagebufCreated signals which carries a pointer to a buff. pFrame is a char* pointer.

    The real_time_image component catch the signal to do somthing.

    But this gives a runtime error:
    qrc:/qml/main.qml:149: Error: Unknown method parameter type: char*

    When I change the pointer pFrame to int, the connection works fine. I also experimented with QObject::Connect, signals can carry pointers, but when it is defined in QML Connection type, the engine does not recognize it.

    Is it a bug or is there a better practice than passing pointers?

    Cheers

    Update: Currently, I walk around this problem by reinterpret char* to int, passing it, then reinterpret it back. It works but Soooooo ugly.

    1 Reply Last reply
    0
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by
      #2

      @mondo said in Signals passing pointer:

      I expect you need to register your c++ type that gets passed to your QML engine (pFrameBuf)
      http://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html#registering-non-instantiable-types

      However, have you seen :
      http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#qbytearray-to-javascript-arraybuffer
      http://doc.qt.io/qt-5/qbuffer.html

      You might find it easier to not use char*'s.

      M 1 Reply Last reply
      2
      • 6thC6 6thC

        @mondo said in Signals passing pointer:

        I expect you need to register your c++ type that gets passed to your QML engine (pFrameBuf)
        http://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html#registering-non-instantiable-types

        However, have you seen :
        http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#qbytearray-to-javascript-arraybuffer
        http://doc.qt.io/qt-5/qbuffer.html

        You might find it easier to not use char*'s.

        M Offline
        M Offline
        mondo
        wrote on last edited by mondo
        #3

        @6thC
        The idea to register any pointer type I use is still not that elegant.

        QbyteArray solves my problem here, it can be passed in signals.
        I'll just need some time to adapt to qt native types.

        Thanks for you help mate.

        1 Reply Last reply
        2
        • 6thC6 Offline
          6thC6 Offline
          6thC
          wrote on last edited by
          #4

          Just have to register the class type (not as a pointer).

          It just needs know about your class type and what to refer to it as.

          // register T
          qmlRegisterUncreatableType<ClassT>("MyClassT"    ,1,0,"MyClassT", "");
          
          // set QML instance to context
          context->setContextProperty(QLatin1Literal("MyClassTIstnaceNamedCpp"), &myCppUncreatableObject);
          

          // QML

          function something(){
            ...
            // call cpp something
            MyClassTIstnaceNamedCpp.something();
          }
          // QML Connection also:
          Connections {
            target: MyClassTIstnaceNamedCpp;
            onSomething: {
              print("cpp something happened");
            }
          }
          

          Sorry it's not all complete but ... hopefully gives you a peek. It's probably possible much easier.

          You can also pass pointers to objects and have QML dynamically create registered CPP class instances - my example has cpp instanced objects and named context... sorry if I'm not explaining very well but I am actually procrastinating myself... on a tight deadline. I shouldn't! Anyhow, good luck.

          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