Qt World Summit: Submit your Presentation

Sharing QCamera object between threads

  • Hello,

    I am having trouble using a webcam in two different classes each of which create their own QCamera object.

    When the second one does QCamera *cam = new QCamera, the debugger shows the message "failed to start". I suppose this is because the resource (webcam) is locked by the first class (in its thread) and it cannot be "taken" by a second.

    As the objects are not used simultaneously, I am thinking of destroying the object one class creates to create another in the other class and "play this game" over and over again. But I suppose this is inneficient and there is a simpler way to share my webcam between two classes.

    Any ideas without having to provide the specific code? A simple example would be much appreciated.

    Thanks in advance!

  • create an independent objects that takes care of interacting with the QCamera then from either of the two treads emit a signal like askForCamera(int) where the argument is an id of the caller, the camera will do it's job and emit another signal for example cameraData(int,QImage) with the result, the first argument is used to determine who the image belongs to

  • @VRonin Thanks for your solution! I am now using a dirtier one. I will eventually apply yours as it is cleaner.

Log in to reply