Camera QML element and multiple QMediaService



  • Hello,
    I have implemented my own QMediaService providing my own camera (a camera simulator). The service is implemented as a plugin very similarly as the Qt's directshow plugin. Now I want to display my camera in Camera item (QML). The QML is as follows:

    ApplicationWindow {
        visible: true
        width: 640
        height: 480
    
        Camera {
               id: camera		   
           }
    
       VideoOutput {
    	   anchors.fill: parent
    	   source: camera
       }
       ListView {
    	   anchors.fill: parent
    	   model: QtMultimedia.availableCameras
    	   delegate: Text {
    		   text: modelData.displayName
    
    		   MouseArea {
    			   anchors.fill: parent
    			   onClicked: camera.deviceId = modelData.deviceId
    		   }
    	   }
       }
    }
    

    It's an example I found somewhere in the Qt Doc. It allows to switch between cameras connected to the PC and display their outputs (live image) on the screen. I have connected two cameras (the first is built-in camera and the second is and USB live cam). The application correctly displays three camera names: the two connected I mentioned and the third is my camera simulator - the QtMultimedia::availableCameras works well. The problem is that when I click on the item with my own camera (the simulator), nothing happens because QMediaServiceProviderPlugin::create() in my plugin is never called. I investigated the QT source codes and I probably found the problem:

    When the Camera element is created by the QtQuick, the QCamera(QObject *parent) constructor is called and it then calls the FIRST QMediaServiceProviderPlugin loaded (the directshow plugin in this case) to create the QMediaService instance. My QMediaService is never created.

    When I try:

    Camera {
       id: camera
       deviceId: QtMultimedia.availableCameras[2].deviceId
    }
    

    it doesn't work from the same reason - the directshow plugin is used to create the QMediaService.

    My question:
    Is there a way how to make the QML program above work for multiple QMediaServiceProviderPlugin loaded?

    Thanks for any usefull help.


  • Lifetime Qt Champion

    Hi,

    One alternative that you can try is to use a wrapper object that provides the QCamera to your VideoOutput.



  • @SGaist
    Thanks for reply. Please could you be more concrete? I don't know how to implement it. A hint would help....


  • Lifetime Qt Champion

    You have to create a QObject subclass that has a property called mediaObject that will return you camera instance.



  • This post is deleted!

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.