[SOLVED] What is wrong with my code when I use QVideoWidget?



  • I use QVideoWideget to show video,but it didn't show video.But at the same time I can hear the sound.
    #include "widget.h"
    #include <QPainter>
    Widget::Widget(QWidget *parent)
    : QWidget(parent)
    {
    setAttribute(Qt::WA_TranslucentBackground);
    myPlayer=new QMediaPlayer;
    videoWidget=new QVideoWidget;
    mainLayout=new QHBoxLayout(this);
    myPlayer->setVideoOutput(videoWidget);
    videoWidget->setFixedSize(400,400);
    myPlayer->setMedia(QUrl::fromLocalFile("D:/next.avi"));
    mainLayout->addWidget(videoWidget);
    myPlayer->play();
    }

    Widget::~Widget()
    {

    }

    This is my code.It doesn't work in my PC,but it can work in my friend‘s PC.
    My OS is Windows 10 X64.



  • Check what QString errorString() returns, that you have proper codec installed.
    Can you watch this avi in other program on your PC?



  • HI and welcome to devnet,

    have you tried to connect a slot to the QMediaPlayer::error() signal?
    You could understand what was wrong (missing video codec??)



  • @alex_malyu Yes,I can play it by other player.Does it due to I have installed two video players?I was in a mess.Maybe something wrong with my computer environment.
    Still thanks!
    P.S. My English is OK?haha



  • Hi,All
    I have solved this problem.Someone told me to install a K-Lite ,I did,and it runs well.
    But in our country,China,we never use this soft.Do I hava to install this? I can not force others who use my soft to install it .



  • Uncompressed avi is portable, but huge.
    Compression is usually done by 3rd party codec.
    Some codecs are installed on the system by default.
    But you need codec to be available on the system if AVI used it.
    Some viewers sometimes integrate codecs.
    That why I assume your other program can play it.

    K-Lite contains mostly widely used codecs.
    If you do not use such codec when creating avi, you do not have to have it installed.

    Fact that after installation


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.