4

My main window is creating another window displayed on a second screen

ApplicationWindow {
    id: mainWindow

    property var customerUi

    Component.onCompleted: {
        customerUi = customerWindow.createObject()
        if (ScreenManager.screenCount() > 1)
            ScreenManager.setScreen(customerUi, 1)
    }
}

Both window need to display a video of the same camera (it is actually a live feed from a usb adaptor, but it works the same)

Camera {
    id: camera
    deviceId: "my_device"
}

VideoOutput {
    source: camera
}

It works fine in one window, but the second window never show the video. I guess because the Camera handle cannot be grabbed by two interface at the same time (or something like that)

I tried creating only one Camera, and two VideoOutput using the same source but it doesn't work either.

I tried to duplicate the view using a ShaderEffect, but

ShaderEffectSource: sourceItem and ShaderEffectSource must both be children of the same window

How can I display the video on both window at the same time ?

EDIT :

Apparently it was possible in Qt 5.3 using ShaderEffectSource https://bugreports.qt.io/browse/QTBUG-43117

But I'm need to make it work with Qt 5.5.1

EDIT 2 :

Duplicating the Video in the same window works fine using ShaderEffectSource, the problem is only to put it in another window.

BlueMagma
  • 2,392
  • 1
  • 22
  • 46

3 Answers3

1

Here is what I did to solve the issue :

I create a third Window wide enough to cover both screen, and duplicate the window using ShaderEffectSource.

This only works because my two Windows are fullscreen on each screen

I'm still looking for an actual solution to the problem, though.

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
BlueMagma
  • 2,392
  • 1
  • 22
  • 46
  • I'm looking for a similar solution with two windows, did you ever figure out something ? – onion Jul 12 '22 at 08:25
  • It's been a while, I don't remember the exact solution but I think we did something directly on the Operating System running the software, maybe we created a virtual camera that was duplicating the feed from the first. If you have control over the execution env and it is linux you could have a look at v4l2 (video for linux 2) – BlueMagma Jul 12 '22 at 15:37
0

You could try Item::grabToImage(callback, targetSize) method to fill static Image with in-memory saved data from source. You'll need 1/60 timer for that also. But I it's quite CPU expensive I believe, so beware :)

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Artem Zaytsev
  • 1,621
  • 20
  • 19
-1

Create two Window items in one main.qml file:

import QtQuick 2.7
import QtQuick.Window 2.2

Item {
    Window {
        title: qsTr("Hello World")
        objectName: "wnd1"
        visible: true
        width: 640
        height: 480
    }

    Window {
        title: qsTr("Hello World 2")
        objectName: "wnd2"
        visible: true
        width: 640
        height: 480
    }
}

Then, load it from your main.cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

You should be able to reuse components easily if it's within the same QML file.

  • I tried your answer and get the problem I expected : you cannot use ShaderEffectSource with a sourceItem living in another Window, even if they are declared in the same QML file – BlueMagma Feb 01 '17 at 13:48
  • Did you try creating two VideoOutput with the same Camera as source attribute? No need for a ShaderEffectSource in order to achieve what you described. – Alexandre Quessy Feb 03 '17 at 20:04