N
N
Nyashkoshkko2013-10-14 00:11:13
Qt
Nyashkoshkko, 2013-10-14 00:11:13

How to make friends QCamera and QGraphicsVideoItem?

There is a code:

#include <QtMultimediaWidgets>

int main(int argc, char *argv[])
{
    QApplication * app = new QApplication(argc,argv);

    QGraphicsView * view = new QGraphicsView();
    QGraphicsScene * scene = new QGraphicsScene();
    QGraphicsVideoItem * item = new QGraphicsVideoItem();
    view->setScene(scene);
    scene->addItem(item);
    view->show();

    QCamera * camera;
    if(QCamera::availableDevices().count() > 0)
    {
        camera = new QCamera();
        camera->setViewfinder(item);
        camera->start();
    }

    return app->exec();
}

It compiles and runs well, the window appears, but at the runtime stage the camera swears:
no video surface, cant start
Camera state changed: QCamera::LoadedState

What can be wrong? Qt 5.1.1, Windows 7 x64

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
epicfailguy93, 2013-10-14
@Nyashkoshkko

I have the same. If you are urgent, then until they fix it, you can do this:

#include <QtGui/QtGui>
#include <QtWidgets/QtWidgets>
#include <QtMultimediaWidgets/QtMultimediaWidgets>

int main(int argc, char *argv[]) {
    QApplication *app = new QApplication(argc,argv);

    QGraphicsView *view = new QGraphicsView();
    QGraphicsScene *scene = new QGraphicsScene();
    QVideoWidget *widget = new QVideoWidget();
    view->setScene(scene);
    scene->addWidget(widget);
    view->show();

    QCamera *camera;
    if(QCamera::availableDevices().count() > 0) {
        camera = new QCamera();
        camera->setViewfinder(widget);
        camera->start();
    }

    return app->exec();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question