How to expose C++ structs for computations to Qml

我与影子孤独终老i 提交于 2019-12-03 10:43:51

Thanks for your help. We decided to use QObject anyway, but in Wrapper-manner. That is, we just built a FixPointWrapper (inheriting QObject), which holds an actual FixedPointValue. That can be used for computations then. Sounds complicated, but works fine. Especially important for our sakes is the possibility, to copy and assign FixedPoint values. Thus, the wrapper is needed.

//QML
MyQmlObject{
    value {mantissa: 2; exponent: 4}
}


//C++
class MyQmlObject : public QQuickItem
{
    Q_Property( FixedPointWrapper* value ... )
}

class FixedPointWrapper : public QObject
{
    ...
    public slots:
       void setValue(FixedPoint){ //Forward to FixedPoint and implement your wanted effect. The same for getter} 
    private:
    FixedPoint value;    
}

In the beginning it felt like a dirty hack, but after we spent a few more thoughts, we can live with the result.

So again, thanks for your help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!