QSGSimpleTextureNode crash application python 3.6 + pyqt5

0

I try to display QImage in my custom widget on QML form. To do this I use QSGSimpleTextureNode class. Here is a simplified example. This code works correctly if we use PySide2, but don't work if we use PyQt5 (the app crashes, "Process finished with exit code -1073741819 (0xC0000005)"). I need to use PyQt5 specifically. Can you tell me where the error is?

main.py

from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine, qmlRegisterType
from img_render import ImageRender
import os


if __name__ == "__main__":
    import sys
    sys_argv = sys.argv

    app = QGuiApplication(sys_argv)

    qmlRegisterType(ImageRender, "ImageRender", 1, 0, "ImageRender")

    engine = QQmlApplicationEngine()
    engine.load('main.qml')

    engine.quit.connect(app.quit)
    sys.exit(app.exec_())

img_render.py

from PyQt5.QtQuick import QQuickItem, QSGNode, QSGSimpleTextureNode
from PyQt5.QtCore import QRectF
from PyQt5.QtGui import QImage


class ImageRender(QQuickItem):
    def __init__(self, parent=None):
        super(ImageRender, self).__init__(parent)
        self.node = None
        self.setFlag(QQuickItem.ItemHasContents, True)

    def updatePaintNode(self, old_node, node_data):
        if self.node is None:
            self.node = QSGNode()
            texture_node = QSGSimpleTextureNode()
            image = QImage("D:/python-projects/cv-image/loadCVImage/images/index.png")
            texture = self.window().createTextureFromImage(image)
            texture_node.setTexture(texture)
            self.node.appendChildNode(texture_node)
        curr_texture = self.node.firstChild()
        curr_texture.setRect(QRectF(0, 0, self.width(), self.height()))
        return self.node

main.qml

import QtQuick 2.9
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.2
import QtQuick.Controls.Material 2.3
import QtQuick.Dialogs 1.2
import QtQuick.Window 2.3
import Qt.labs.platform 1.0 as Platform
import ImageRender 1.0

ApplicationWindow {
    width: 600
    height: 600
    visible: true

    ImageRender {
        id: imageRender
        anchors.fill: parent
    }
}
python
qml
pyqt5
qimage

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0