E
E
Egorithm2020-07-05 13:27:43
Qt
Egorithm, 2020-07-05 13:27:43

Why doesn't Qt application start with QVideoWidget?

At first I tried to run MP4. But there, it seems, there is no codec, and you will need to deal with the codec separately.
But then I read that on Windows for AVI, the codec should be present by default. And, it seems, it does not crash with an error, as with MP4. Ie, apparently, there is a codec, but just the window is not even displayed.

I don't understand what's the matter.

Here is the code:

main:
#include "header.hpp"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

header:
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP

#include <QWidget>
#include <QGridLayout>

#include <QVideoWidget>
#include <QMediaPlayer>
#include <QVideoProbe>

class MainWindow : public QWidget
{
Q_OBJECT

private:
    QGridLayout *main_window_layout;

    QVideoWidget *video_widget;
    QMediaPlayer *media_player;
    QVideoProbe  *video_probe;

public:
    explicit MainWindow(QWidget *parent = nullptr);
    MainWindow(const MainWindow &other) = delete;
    MainWindow(MainWindow &&other) = delete;
    ~MainWindow() = default;
    MainWindow& operator=(const MainWindow &other) = delete;
    MainWindow& operator=(MainWindow &&other) = delete;
};

#endif // MAINWINDOW_HPP

source:
#include "header.hpp"

#include <QUrl>
#include <QString>
#include <string>

MainWindow::MainWindow(QWidget *parent)
    : QWidget{parent}
{
    main_window_layout = new QGridLayout{this};

    video_widget = new QVideoWidget{this};
    media_player = new QMediaPlayer{this};
    video_probe  = new QVideoProbe{this};

    this->setMaximumWidth(500);
    this->setMinimumHeight(400);

    main_window_layout->addWidget(video_widget,0,0,1,1);
    main_window_layout->setContentsMargins(0,0,0,0);
    main_window_layout->setSpacing(0);

    media_player->setVideoOutput(video_widget);

    media_player->setMedia(
        QUrl::fromLocalFile(
            QString::fromStdWString(
                std::wstring{L"C:/Users/march/Desktop/1.avi"})));

    video_probe->setSource(media_player);
    media_player->play();
}


Thanks for the help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ananiev, 2020-07-05
@SaNNy32

AVI is a container, it can contain any codec. Does this file play in windows media player?

E
Egorithm, 2020-07-05
@EgoRusMarch

The easiest way to fix codec problem on Windows is to install K-Lite Codec Pack Basic .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question