Qt/QML : Send QImage From C++ to QML and Display The QImage On GUI

后端 未结 4 921
执念已碎
执念已碎 2020-12-23 11:34

I created a class Publisher which periodically emits a QImage object.

However I\'m having a tough time drawing the QImage to

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 12:15

    Use QQuickItem. There is a Qt example that does this.

    C:\Qt\Examples\Qt-5.14.1\quick\scenegraph\threadedanimation

    You make a class derived from QQuickItem and register it with qmlRegisterType. Provide the override function 'updatePaintNode' in your class. In the example, the class is 'Spinner'

    In updatePaintNode:

    Create a node class derived from QObject and QSGTransformNode

    In the node class constructor:

    Convert your Qimage to an QSGTexture with createTextureFromImage.

    Create QSGSimpleTextureNode, set QSGTexture using setTexture

    appendChildNode with QSGSimpleTextureNode

    In QML add

    import Spinner 1.0
    

    and

    Spinner {
        anchors.centerIn: parent
        anchors.horizontalCenterOffset: 80
        spinning: true
    }
    

提交回复
热议问题