uint8_t and friends on QML
-
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?
-
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?
@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. -
@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.@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-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).@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.