赞
踩
报错原代码:
m_videoWidget = new QVideoWidget(this);
m_videoWidget = new QVideoWidget(this);
报错:error: invalid use of incomplete type ‘class QVideoWidget’
m_videoWidget = new QVideoWidget(this);
^
#include <QWidget>
#include <QtMultimediaWidgets>
或 #include <QVideoWidget>
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QVideoWidget> #include <QMediaPlayer> #include <QMediaPlaylist> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); protected: QMediaPlayer *m_player = nullptr; QMediaPlaylist *m_playlist = nullptr; QVideoWidget *m_videoWidget = nullptr; }; #endif // MAINWINDOW_H
#include "mainwindow.h" #include <QMediaMetaData> #include <QtWidgets> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setMinimumSize(1200,1000); m_player = new QMediaPlayer(this); m_player->setAudioRole(QAudio::VideoRole); m_videoWidget = new QVideoWidget(this); m_player->setVideoOutput(m_videoWidget); m_videoWidget->move(100,100); m_videoWidget->resize(700,440); m_videoWidget->setAspectRatioMode(Qt::IgnoreAspectRatio); QBoxLayout *displayLayout = new QHBoxLayout; displayLayout->addWidget(m_videoWidget, 2); QString spath("E:\\data\\code\\Qt_project_try\\03_QDialog\\video\\3min.wmv"); QUrl pathurl = QUrl::fromUserInput(spath); m_player->setMedia(pathurl); m_player->play(); QPushButton *btn =new QPushButton; QPushButton *openButton = new QPushButton(tr("muda"), this); btn->setParent(this); btn->setText("sb"); btn->move(30,300); btn->resize(50,50); QBoxLayout *layout = new QVBoxLayout; layout->addLayout(displayLayout); layout->addWidget(openButton); layout->addWidget(btn); setLayout(layout); connect(btn,&QPushButton::clicked,[=](){ m_player->setMedia(pathurl); m_player->play(); qDebug() << "通过按键视频也能播放"; }); } MainWindow::~MainWindow() { }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。