I'm trying to use the QMediaPlayer
and QVideoWidget
to display a video on a system I'm producing. Except that these class rays do not work as expected. QVideoWidget
simply does not appear, does not display the video, does nothing!
The MCVE
To exemplify the problem, I built a Minimum, Full, and Verifiable Example based in the Qt 5 documentation example itself . Below are the configuration files for CMake (for setting the environment - that is, creating the Visual Studio or Makefile project) and code :
CMakeLists.txt :
cmake_minimum_required(VERSION 2.8.11)
project (Teste)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
# Configuração do Qt
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5MultimediaWidgets REQUIRED)
# Cria o executável
if(WIN32)
add_executable(Teste WIN32 main.cpp)
else()
add_executable(Teste main.cpp)
endif()
# Adiciona as bibliotecas necessárias
target_link_libraries(Teste Qt5::Widgets Qt5::Multimedia Qt5::MultimediaWidgets)
main.cpp :
#include <QApplication>
#include <QMediaPlayer>
#include <QVideoWidget>
#include <QMediaPlaylist>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QMediaPlayer *player;
QMediaPlaylist *playlist;
QVideoWidget *videoWidget;
// Código tirado do exemplo em: http://doc.qt.io/qt-5/qvideowidget.html#details
// -------------------------
player = new QMediaPlayer;
playlist = new QMediaPlaylist(player);
playlist->addMedia(QUrl("http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4"));
playlist->addMedia(QUrl("http://techslides.com/demos/sample-videos/small.mp4"));
videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
playlist->setCurrentIndex(1);
player->play();
// -------------------------
return app.exec();
}
The Problem
When I run the code, the component ( QVideoWidget
) apparently is not "created" (although it is displayed, since to ensure that the problem is not another I call show
directly on the wretch), since window appears "shortened" (without any standard size):
ButevenifIusethemousetoresizethewindow,nothingisdisplayed:
Thecodegeneratesnoexceptionsorerrors.IntheminimalexampleIuseURLsofvideosjusttomaketestingeasier(andasitisinthedocumentation),butonmylocalsystemIreadlocalfilesandtheproblemisexactlythesame.
TheEnvironment
Mydevelopmentenvironmentis:
- Windows1064-bit
- CMake3.5.0-rc3
- Qt5.6.032bit
- VisualStudio2015
EDIT
IjusttestedinUbuntu(16.0464bit)withQt5.7(64bit)andtheproblemisexactlythesame: