简体   繁体   English

QT QMediaPlayer窗口小部件导致白色小窗口

[英]QT QMediaPlayer Widget causes small white window

I want to add a videoplayer inside of a qtabwidget in my .ui form file. 我想在.ui表单文件中的qtabwidget中添加视频播放器。 When the program is ran (Windows 8) the program window is a small white box (not what my .ui form is) and the video plays (you can hear it). 当程序运行时(Windows 8),程序窗口是一个小白框(不是我的.ui窗体),并且视频播放(您可以听到)。 Also, if I comment out everything after “ui->Information->addTab(videoWidget, “video”);” the program's UI loads like normal and the new tab is created “video”, however nothing works cause the mediaPlayer code is commented out. 另外,如果我注释掉“ ui-> Information-> addTab(videoWidget,“ video”);”之后的所有内容,则程序的UI像正常加载一样,并且新选项卡被创建为“ video”,但是没有任何作用,因为mediaPlayer代码被注释了出来。 This is the code for the media widget: 这是媒体窗口小部件的代码:

mainwin.h mainwin.h

private:
    QMediaPlayer * mediaPlayer;

mainwin.cpp mainwin.cpp

ui->setupUi(this);
mediaPlayer = new QMediaPlayer();
QVideoWidget *videoWidget = new QVideoWidget();
ui->Information->addTab(videoWidget, "video");
mediaPlayer->setVideoOutput(videoWidget);
mediaPlayer->setMedia(QUrl("link"));
mediaPlayer->play();

Can someone help? 有人可以帮忙吗? Thanks! 谢谢!

EDIT: Looking over examples from qt I noticed "mediaPlayer(0, QMediaPlayer::VideoSurface)" when the window is being created if I were to do this I would get: 编辑:查看来自qt的示例时,在创建窗口时,我注意到“ mediaPlayer(0,QMediaPlayer :: VideoSurface)”,如果这样做,我会得到:

Project::Project(QWidget *parent) :
QMainWindow(parent),
mediaPlayer(0, QMediaPlayer::VideoSurface),
ui(new Ui::Project)
{
ui->setupUi(this);

This results in a few errors, "error: expression list treated as compound expression in mem-initializer [-fpermissive] mediaPlayer(0, QMediaPlayer::VideoSurface)", "warning: left operand of comma operator has no effect [-Wunused-value]", and "error: cannot convert 'QMediaPlayer::Flag' to 'QMediaPlayer*' in initialization". 这会导致一些错误,“错误:表达式列表在mem-initializer [-fpermissive] mediaPlayer(0,QMediaPlayer :: VideoSurface)中被视为复合表达式”,“警告:逗号运算符的左操作数无效[-Wunused-值]和“错误:初始化时无法将'QMediaPlayer :: Flag'转换为'QMediaPlayer *'”。

I had the same problem after embedding the complete QT media player example in my QT 5.5.0 project. 将完整的QT媒体播放器示例嵌入到QT 5.5.0项目中后,我遇到了同样的问题。 After starting playing the video, a white box would show up in left-top corner. 开始播放视频后,左上角会出现一个白色框。

I noticed that the player would actually make my application toolbar (partially) white, but if the toolbar was hidden, it would add the white box. 我注意到播放器实际上会使我的应用程序工具栏(部分)变成白色,但是如果工具栏被隐藏,它将添加白色框。

Since I did not need the toolbar, I fixed this by removing the toolbar instead of hiding it. 由于不需要工具栏,因此我通过删除工具栏而不是隐藏工具栏来解决此问题。 In QT designer, right-click in the toolbar, then "Remove Toolbar ". 在QT设计器中,右键单击工具栏,然后单击“删除工具栏”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM