ASSERT:播放视频时显示“m_surface”
ASSERT: “m_surface” when play a video
我有两个类似的代码,但略有不同。在第一个代码中,我通过在构造函数中调用 play()
函数直接播放视频,在第二个代码中,我在按钮单击事件中调用播放函数。
第二个代码可以正确播放视频,但第一个代码显示这个 run-time 错误:
第一个代码有什么问题?
这是我的第一个代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene;
ui->graphicsView->setScene(scene);
mp1.setVideoOutput(&v1);
QString foo("C:/Users/user/Desktop/files/1.mov");
play(QUrl(foo));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::play(QUrl url)
{
mp1.setMedia(url);
mp1.play();
mp1.setVolume(0);
scene->addItem(&v1);
}
这是我的第二个代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene;
ui->graphicsView->setScene(scene);
mp1.setVideoOutput(&v1);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::play(QUrl url)
{
mp1.setMedia(url);
mp1.play();
mp1.setVolume(0);
scene->addItem(&v1);
}
void MainWindow::on_pushButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"");
play(fileName);
}
更多详情:
- os: windows 7 64 位
- 编译器:mscv2013 64 位
- mp1:QMediaPlayer
- v1:QGraphicsVideoItem
由于您是从构造函数中调用 play
,似乎有些东西还没有完全初始化,这导致断言失败。
要对此进行测试,请尝试将以下函数添加到 slots:
部分中的 MainWindow
:
void MainWindow::playVideo()
{
QString foo("C:/Users/user/Desktop/files/1.mov");
play(QUrl(foo));
}
并在 MainWindow
构造函数中执行以下操作:
QTimer::singleShot(0, this, SLOT(playVideo()));
而不是直接调用 play
。
我有两个类似的代码,但略有不同。在第一个代码中,我通过在构造函数中调用 play()
函数直接播放视频,在第二个代码中,我在按钮单击事件中调用播放函数。
第二个代码可以正确播放视频,但第一个代码显示这个 run-time 错误:
第一个代码有什么问题?
这是我的第一个代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene;
ui->graphicsView->setScene(scene);
mp1.setVideoOutput(&v1);
QString foo("C:/Users/user/Desktop/files/1.mov");
play(QUrl(foo));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::play(QUrl url)
{
mp1.setMedia(url);
mp1.play();
mp1.setVolume(0);
scene->addItem(&v1);
}
这是我的第二个代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene;
ui->graphicsView->setScene(scene);
mp1.setVideoOutput(&v1);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::play(QUrl url)
{
mp1.setMedia(url);
mp1.play();
mp1.setVolume(0);
scene->addItem(&v1);
}
void MainWindow::on_pushButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"");
play(fileName);
}
更多详情: - os: windows 7 64 位 - 编译器:mscv2013 64 位 - mp1:QMediaPlayer - v1:QGraphicsVideoItem
由于您是从构造函数中调用 play
,似乎有些东西还没有完全初始化,这导致断言失败。
要对此进行测试,请尝试将以下函数添加到 slots:
部分中的 MainWindow
:
void MainWindow::playVideo()
{
QString foo("C:/Users/user/Desktop/files/1.mov");
play(QUrl(foo));
}
并在 MainWindow
构造函数中执行以下操作:
QTimer::singleShot(0, this, SLOT(playVideo()));
而不是直接调用 play
。