To write the C++ code for video players, we perform the following steps:
- For mainwindow.h, there aren't many changes to it. All we need to do is to include QVideoWidget in the header:
#include <QMainWindow> #include <QDebug> #include <QFileDialog> #include <QMediaPlayer> #include <QMediaMetaData> #include <QTime> #include <QVideoWidget>
- Then, open mainwindow.cpp. We must define a QVideoWidget object and set it as the video output target, before adding it to the layout of the QFrame object we just added in the previous step:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); player = new QMediaPlayer(this); QVideoWidget* videoWidget = new QVideoWidget(this); ...