-2

I tried to show video using QGraphicView but my code doesn't show anything. What is the problem

QGraphicsScene scene;
QGraphicsVideoItem *item1 = new QGraphicsVideoItem;
item1->setPos(0,100);

QMediaPlayer * player1 = new QMediaPlayer;
player1->setVideoOutput(item1);
player1->setMedia(QUrl("/home/1.wmv"));
QGraphicsView view;
view.scale(0.3,0.3);
view.setScene(&scene);
view.show();
player1->play();
Ali
  • 9
  • change to `QGraphicsScene *scene = new QGraphicsScene;` and `QGraphicsView *view = new QGraphicsView(scene);`, provide a [mre] – eyllanesc Aug 02 '19 at 07:53

2 Answers2

0

You are creating a QGraphicsVideoItem which you are using as output for a QMediaPlayer and are creating a QGraphicsView on which you assign a QGraphicsScene. But you are not connecting the QGraphicsVideoItem (or the QMediaPlayer) to the QGraphicsView (or the QGraphicsScene), so obviously nothing gets shown in the QGraphicsView.

Note this is only a guesswork answer based on the incomplete code you provided. In the future, please be sure to include all relevant code/create a Minimal, Reproducible Example

CharonX
  • 2,130
  • 11
  • 33
0

You forgott:

scene->addItem(item1);
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QGraphicsScene * scene = new QGraphicsScene();
    QGraphicsView * view = new QGraphicsView(scene);

    QGraphicsVideoItem *item1 = new QGraphicsVideoItem;
    QMediaPlayer * player1 = new QMediaPlayer;

    scene->addItem(item1);
    item1->setPos(0,100);

    view->scale(0.3,0.3);
    view->show();

    player1->setVideoOutput(item1);
    player1->setMedia(QUrl::fromLocalFile("/home/user/Musik/musik.mp4"));

    player1->play();

    return a.exec();
}


Altinsystems
  • 186
  • 2
  • 8