Creating a QVideoWidget in Qt5

3.9k Views Asked by At

I have the following piece of code:

#include <QtWidgets/QtWidgets>
#include <QtMultimedia/QCamera>
#include <QtMultimedia/QMediaPlayer>

int main(int argc, char * argv[])
{
    QApplication testQt(argc, argv);
    QMainWindow w;

    QWidget videoContainer(&w);
    w.setCentralWidget(&videoContainer);

    QVideoWidget videoWidget(&videoContainer);

    QCamera cam(&w);
    cam.setViewfinder(&videoWidget);
    cam.start();

    w.show();

    return testQt.exec();
}

in which I am trying to create a main window, create a container widget to display video, create a videowidget in that container, and then finally set the viewfinder of the camera to that videowidget. However, when I try to do this I get the error

Variable has incomplete type 'QVideoWidget'

Why am I getting this error?

1

There are 1 best solutions below

4
On BEST ANSWER

You need to include the corresponding header as follows:

#include <QVideoWidget>

You may also need to add this to your project file:

QT += multimediawidgets