EgoRusMarch
@EgoRusMarch
C++ Developer

Почему не запускается приложение Qt с QVideoWidget?

Сначала пробовал запустить MP4. Но там, вроде как, нет кодека и с кодеком нужно будет отдельно разбираться.
Но потом прочитал что на Винде для AVI кодек должен присутствовать по умолчанию. И, вроде бы, с ошибкой не падает, как с MP4. Т.е, видимо, кодек есть, но просто окно даже не отображается.

Не понимаю, в чём дело.

Вот код:
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();
}


Спасибо за помощь.
  • Вопрос задан
  • 169 просмотров
Пригласить эксперта
Ответы на вопрос 2
AVI это контейнер, в нем кодек может быть любой. В windows media player этот файл проигрывается?
Ответ написан
EgoRusMarch
@EgoRusMarch Автор вопроса
C++ Developer
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы