Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. I have a problem with pyqt6 type object 'QQuickImageProvider' has no attribute 'Image', how can I solve it?
Forum Updated to NodeBB v4.3 + New Features

I have a problem with pyqt6 type object 'QQuickImageProvider' has no attribute 'Image', how can I solve it?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
12 Posts 3 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F film

    I have a problem with pyqt6 type object 'QQuickImageProvider' has no attribute 'Image', how can I solve it?
    alt text

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #2

    @film
    Count it be QQmlImageProviderBase.Image instead?

    SGaistS 1 Reply Last reply
    0
    • JonBJ JonB

      @film
      Count it be QQmlImageProviderBase.Image instead?

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi,

      Which version of PySide6 are you using ?
      Tested with 6.4.2 and 6.5.0 and it's working as expected.

      Next time, please post your code as text so it's easier to use it for testing.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        Which version of PySide6 are you using ?
        Tested with 6.4.2 and 6.5.0 and it's working as expected.

        Next time, please post your code as text so it's easier to use it for testing.

        F Offline
        F Offline
        film
        wrote on last edited by film
        #4

        @SGaist my code main.py

        import sys
        from PyQt6.QtCore import *
        from PyQt6.QtGui import *
        from PyQt6.QtQml import *
        from PyQt6.QtQuick import *
        
        
        class MyImageProvider(QQuickImageProvider):
            def __init__(self):
                super(MyImageProvider, self).__init__(QQuickImageProvider.Image)
        
            def requestImage(self, p_str, size):
                img = QImage(300, 300, QImage.Format.Format_BGR888)
                img.fill(Qt.green)
                return img, img.size()
        
        
        if __name__ == '__main__':
            app = QGuiApplication(sys.argv)
        
            engine = QQmlApplicationEngine()
            engine.addImageProvider("myprovider", MyImageProvider())
            engine.load(QUrl.fromLocalFile("main.qml"))
            if len(engine.rootObjects()) == -1:
                sys.exit(-1)
            sys.exit(app.exec())
        
        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Which version of PySide6 are you using ?
          Tested with 6.4.2 and 6.5.0 and it's working as expected.

          Next time, please post your code as text so it's easier to use it for testing.

          F Offline
          F Offline
          film
          wrote on last edited by
          #5

          @SGaist main.qml

          import QtQuick 2.15
          import QtQuick.Controls 2.15
          
          ApplicationWindow {
              visible: true
              width: 640
              height: 480
              title: "Display Image"
              
              Image {
                  id: image
                  width: parent.width
                  height: parent.height
                  source: image // Context property created in Python code
              }
          }
          
          
          SGaistS 1 Reply Last reply
          0
          • F film

            @SGaist main.qml

            import QtQuick 2.15
            import QtQuick.Controls 2.15
            
            ApplicationWindow {
                visible: true
                width: 640
                height: 480
                title: "Display Image"
                
                Image {
                    id: image
                    width: parent.width
                    height: parent.height
                    source: image // Context property created in Python code
                }
            }
            
            
            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #6

            You forgot to mention which version of PySide PyQt 6 you are using.

            Also, how did you install it ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            F 1 Reply Last reply
            0
            • SGaistS SGaist

              You forgot to mention which version of PySide PyQt 6 you are using.

              Also, how did you install it ?

              F Offline
              F Offline
              film
              wrote on last edited by
              #7

              @SGaist
              I want to use pyqt6 because it has to be bundled with the project. please guide me

              SGaistS 1 Reply Last reply
              0
              • F film

                @SGaist
                I want to use pyqt6 because it has to be bundled with the project. please guide me

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Sorry, I misread the imports.

                Anyway, the solution to your issue:

                class MyImageProvider(QQuickImageProvider):
                    def __init__(self):
                        super(MyImageProvider, self).__init__(QQuickImageProvider.ImageType.Image)
                
                    def requestImage(self, p_str, size):
                        img = QImage(300, 300, QImage.Format.Format_BGR888)
                        img.fill(Qt.green)
                        return img, img.size()
                
                

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                F 2 Replies Last reply
                1
                • SGaistS SGaist

                  Sorry, I misread the imports.

                  Anyway, the solution to your issue:

                  class MyImageProvider(QQuickImageProvider):
                      def __init__(self):
                          super(MyImageProvider, self).__init__(QQuickImageProvider.ImageType.Image)
                  
                      def requestImage(self, p_str, size):
                          img = QImage(300, 300, QImage.Format.Format_BGR888)
                          img.fill(Qt.green)
                          return img, img.size()
                  
                  
                  F Offline
                  F Offline
                  film
                  wrote on last edited by
                  #9
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Sorry, I misread the imports.

                    Anyway, the solution to your issue:

                    class MyImageProvider(QQuickImageProvider):
                        def __init__(self):
                            super(MyImageProvider, self).__init__(QQuickImageProvider.ImageType.Image)
                    
                        def requestImage(self, p_str, size):
                            img = QImage(300, 300, QImage.Format.Format_BGR888)
                            img.fill(Qt.green)
                            return img, img.size()
                    
                    
                    F Offline
                    F Offline
                    film
                    wrote on last edited by
                    #10

                    @SGaist
                    now i got code like this i want cv2 to show in ui qml page more solution please help me

                    main.py

                    import sys
                    from pathlib import Path
                    import os
                    import cv2
                    
                    from PyQt6.QtGui import QGuiApplication
                    from PyQt6.QtQml import QQmlApplicationEngine
                    from PyQt6.QtGui import QIcon, QPixmap, QImage
                    from PyQt6.QtWidgets import QFileDialog, QApplication
                    from PyQt6.QtCore import Qt, QThread, pyqtSignal, pyqtSlot, QObject, QSize
                    from PyQt6.QtQuick import QQuickPaintedItem, QQuickView, QQuickImageProvider
                    
                    class ThreadCamera(QThread):
                        updateFrame = pyqtSignal(QImage)
                    
                        def __init__(self, parent=None):
                            QThread.__init__(self, parent)
                        
                        def run(self):
                            self.cap = cv2.VideoCapture(0)
                            while self.cap.isOpened():
                                ret, frame = self.cap.read()
                                if not ret:
                                    img = QImage("./images/network.png")
                                    self.updateFrame.emit(img)
                                color_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
                                img = QImage(color_frame.data, color_frame.shape[1], color_frame.shape[0], QImage.Format.Format_RGB888)
                                self.updateFrame.emit(img)
                    
                    
                    
                    class ImageProvider(QQuickImageProvider):
                        imageChanged = pyqtSignal(QImage)
                    
                        def __init__(self):
                            super(ImageProvider, self).__init__(QQuickImageProvider.ImageType.Image)
                    
                            self.cam = ThreadCamera() 
                            self.cam.updateFrame.connect(self.update_image)
                            self.image = None
                    
                        def requestImage(self, id, size):
                            if self.image:
                                img = self.image
                            else:
                                img = QImage(600, 500, QImage.Format.Format_RGBA8888)
                                img.fill(Qt.GlobalColor.black)
                    
                            return img,img.size()
                    
                              
                        @pyqtSlot()
                        def update_image(self, img):
                            self.imageChanged.emit(img)
                            self.image = img
                        
                        @pyqtSlot()
                        def start(self):
                            print("Starting...")
                            self.cam.start()
                        
                        @pyqtSlot()
                        def killThread(self):
                            print("Finishing...")
                            try:
                                self.cam.cap.release()
                                cv2.destroyAllWindows()
                            except:
                                pass
                    
                    
                    
                    class MainWindow(QObject):
                        def __init__(self):
                            QObject.__init__(self)
                        
                    
                    if __name__ == "__main__":
                        app = QApplication(sys.argv)
                        app.setWindowIcon(QIcon("./images/network.png"))
                        engine = QQmlApplicationEngine()
                    
                        #Get Context
                        main = MainWindow()
                        myImageProvider = ImageProvider()
                        engine.rootContext().setContextProperty("backend", main)
                        engine.rootContext().setContextProperty("myImageProvider", myImageProvider)
                        
                        engine.addImageProvider("MyImageProvider", myImageProvider)
                    
                        #Load QML File
                        engine.load(os.fspath(Path(__file__).resolve().parent /  "main.qml"))
                    
                        if not engine.rootObjects():
                            sys.exit(-1)
                        sys.exit(app.exec())
                    

                    main.qml

                    import QtQuick 6.3
                    import QtQuick.Window 6.3
                    import QtMultimedia 6.3
                    import QtQuick.Controls 6.3
                    import QtQuick.Layouts 6.3
                    import QtQuick.Dialogs 6.3
                    
                    
                    
                    
                    Window {
                        visible: true
                        width: 600
                        height: 500
                        title: "WebCam"
                        Image {
                            id: feedImage
                            width: parent.width
                            height: parent.height - 50
                            fillMode: Image.PreserveAspectFit
                            cache: false
                            source: "image://MyImageProvider/img"
                            property bool counter: false
                    
                            function reloadImage() {
                                counter = !counter
                                source = "image://MyImageProvider/img?id=" + counter
                            }
                        }
                    
                        RowLayout {
                            anchors.top: feedImage.bottom
                            anchors.horizontalCenter: feedImage.horizontalCenter
                    
                            Button {
                                id: btnStartCamera
                                text: "Start Camera"
                                onClicked: {
                                    myImageProvider.start()
                                }
                            }
                            
                            Button {
                                id: btnStopCamera
                                text: "Stop Camera"
                                onClicked: {
                                    myImageProvider.killThread()
                                 }
                            }
                    
                    
                        }
                    
                        
                        Connections{
                            target: myImageProvider
                    
                            function onImageChanged(image) {
                                console.log("emit")
                                feedImage.reloadImage()
                            }
                                
                        }
                    
                    }
                    
                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      film
                      wrote on last edited by
                      #11

                      @SGaist
                      Now there is an issue with TypeError: update_image() missing 1 required positional argument: 'img'.
                      which if I use PySide6 it works but I want to use it with PyQt6 because it has to be merged with the created project.

                      SGaistS 1 Reply Last reply
                      0
                      • F film

                        @SGaist
                        Now there is an issue with TypeError: update_image() missing 1 required positional argument: 'img'.
                        which if I use PySide6 it works but I want to use it with PyQt6 because it has to be merged with the created project.

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        You did not specify the type of the argument if your slot in pyqtSlot.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved