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. uint8_t and friends on QML
Forum Updated to NodeBB v4.3 + New Features

uint8_t and friends on QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 2.4k 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.
  • G Offline
    G Offline
    GRAlves
    wrote on last edited by GRAlves
    #1

    Hi,

    I have a C++ class with several slots with signatures like void slotname(uint8_t arg1, uint16_t arg2). I would like to call those slots from QML. I have successfully exposed an object of this class to the QML engine, but when I try to call the method with :

    slotname(1,2)
    

    from QML I get the following error:

    Error: Unknown method parameter type: uint8_t
    

    What is the correct way to expose uint8_t and friends types to qml?

    raven-worxR 1 Reply Last reply
    0
    • G GRAlves

      Hi,

      I have a C++ class with several slots with signatures like void slotname(uint8_t arg1, uint16_t arg2). I would like to call those slots from QML. I have successfully exposed an object of this class to the QML engine, but when I try to call the method with :

      slotname(1,2)
      

      from QML I get the following error:

      Error: Unknown method parameter type: uint8_t
      

      What is the correct way to expose uint8_t and friends types to qml?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @GRAlves
      see this
      uint8_t is way to specific for QML (the JS engine in specific). Or set the slot parameter type to QVariant and let QML do the conversation. Then if you really like you can get a uint8_t out of the QVariant. But in every case you never can guarantee that the types are the same between C++ and QML.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      G 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @GRAlves
        see this
        uint8_t is way to specific for QML (the JS engine in specific). Or set the slot parameter type to QVariant and let QML do the conversation. Then if you really like you can get a uint8_t out of the QVariant. But in every case you never can guarantee that the types are the same between C++ and QML.

        G Offline
        G Offline
        GRAlves
        wrote on last edited by
        #3

        @raven-worx
        Is there a way to register a "default conversion" from QVariant to uint8_t, throwing exceptions if it is out of range? I have over 200 slots that use uint8 and friends and I don't want to change the signature of them (would impact a lot of existing code).

        raven-worxR 1 Reply Last reply
        0
        • G GRAlves

          @raven-worx
          Is there a way to register a "default conversion" from QVariant to uint8_t, throwing exceptions if it is out of range? I have over 200 slots that use uint8 and friends and I don't want to change the signature of them (would impact a lot of existing code).

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @GRAlves said in uint8_t and friends on QML:

          Is there a way to register a "default conversion" from QVariant to uint8_t, throwing exceptions if it is out of range?

          no and no.
          You can write a script which does a regex replacement for all parameters to int type.
          Or depending on your code design it may be possible to introduce a "wrapper slot / invokable method"? Then expose this object to QML which forwards the calls to your existing class.

          But there is no solution for a clean integration without changing your code. The JS- and C++ world are just not fully compatible.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          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