在网上没找到,在书上也没有。后来突然想直接在官网的类里面找Video 居然就有了。
把的例子补充完整后就可以运行了。
注意pro文件中要添加内容,还有各种必要的头文件要添加。
开发环境Qt 5.3.2
代码如下:
pro文件
QT += core gui\ multimedia\ multimediawidgetsgreaterThan(QT_MAJOR_VERSION, 4): QT += widgets\TARGET = Video_TryTEMPLATE = appSOURCES += main.cpp\ mainwindow.cppHEADERS += mainwindow.hFORMS += mainwindow.ui
mainwindow.h
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include#include #include #include #include class MainWindow : public QMainWindow{ Q_OBJECTpublic: QMediaPlaylist * playlist; QMediaPlayer * player; QVideoWidget * videoWidget; MainWindow(); ~MainWindow();};#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(){ playlist = new QMediaPlaylist; player = new QMediaPlayer; videoWidget = new QVideoWidget; setCentralWidget(videoWidget); playlist->addMedia(QUrl::fromLocalFile("D:/Users/Qt_project/Video_Try/3.avi")); playlist->setCurrentIndex(1); player->setPlaylist(playlist); player->setVideoOutput(videoWidget); videoWidget->show(); player->play();}MainWindow::~MainWindow(){}
main
#include "mainwindow.h"#includeint main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();}