Home > other >  How to pass uint32_t * as a property to QML
How to pass uint32_t * as a property to QML

Time:10-04

I want to pass an of array of uint32_t to QML as a property of uint32_t*

Q_PROPERTY(uint32_t *Data READ Data WRITE setData NOTIFY DataChanged)

but I got an error

QMetaProperty::read: Unable to handle unregistered datatype 'uint32_t*' for property 'mpk::mssc::gui::HistogramController::histogramData'

How can I pass uint32_t* to QML code using Q_PROPERTY?

CodePudding user response:

I don't think you can use a C array in QML. What you can do is create a QList from that array and expose it like a property. In that case you'll be able to treat it like a JS array.

Q_PROPERTY(QList<unsigned int> data READ data WRITE setData NOTIFY dataChanged)

Also note that you won't be able to get notifications for elements changing or of changes of the QList itself. To get notifications and use for bindings you'll have to reset the entire QList.

Another option would be to wrap your array with proper invokable methods:

Q_INVOKABLE unsigned int getElement(int i)
Q_INVOKABLE void setElement(int i, unsigned int val)
Q_INVOKABLE void appendElement(unsigned int val)
...
  • Related