Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GraphicsView crash with GraphicsVideoItem.
Forum Updated to NodeBB v4.3 + New Features

GraphicsView crash with GraphicsVideoItem.

Scheduled Pinned Locked Moved Solved General and Desktop
mediaplayergraphicviewqgraphicsvideoiform
3 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fidchells_Eye
    wrote on 24 Jun 2016, 14:58 last edited by
    #1

    Hi
    I've been trying my hand at building a simple media player with the form for object placement.
    But it crashes just as it starts to run.


    Constructor Code:
    ui->setupUi(this);
    videoItem = new QGraphicsVideoItem();

    ui->GVpreview->scene()->addItem(videoItem); // << --- Trouble maker that causes crash
    ui->GVpreview->show(); // GVpreview = QGraphicsView

    connect(ui->hsdrDuration, SIGNAL(sliderMoved(int)), this, SLOT(setPosition(int)));
    mediaPlayer.setVideoOutput(videoItem);
    connect(&mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)),this, SLOT(mediaStateChanged(QMediaPlayer::State)));


    For some reason the crash happens at ui->GVpreview->scene()->addItem(videoItem); and don't know why or how to fix it.

    Thank you for your replies and time.

    J 1 Reply Last reply 24 Jun 2016, 15:01
    0
    • F Fidchells_Eye
      24 Jun 2016, 14:58

      Hi
      I've been trying my hand at building a simple media player with the form for object placement.
      But it crashes just as it starts to run.


      Constructor Code:
      ui->setupUi(this);
      videoItem = new QGraphicsVideoItem();

      ui->GVpreview->scene()->addItem(videoItem); // << --- Trouble maker that causes crash
      ui->GVpreview->show(); // GVpreview = QGraphicsView

      connect(ui->hsdrDuration, SIGNAL(sliderMoved(int)), this, SLOT(setPosition(int)));
      mediaPlayer.setVideoOutput(videoItem);
      connect(&mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)),this, SLOT(mediaStateChanged(QMediaPlayer::State)));


      For some reason the crash happens at ui->GVpreview->scene()->addItem(videoItem); and don't know why or how to fix it.

      Thank you for your replies and time.

      J Offline
      J Offline
      Joel Bodenmann
      wrote on 24 Jun 2016, 15:01 last edited by Joel Bodenmann
      #2

      Is it possible that you forgot to create and/or assign the scene to the view?
      Unless you can do that in the QtDesigner you have to do something like this:

      // This creates the QGraphicsView, but there's still no QGraphicsScene!
      ui->setupUi(this);
      
      // Create and assign the QGraphicsScene
      QGraphicsScene* scene = new QGraphicsScene(this);
      ui->GVpreview->setScene(scene);
      
      // Fun can start here
      videoItem = new QGraphicsVideoItem();
      ui->GVpreview->scene()->addItem(videoItem);
      

      In general you have to check the pointer returned by QGraphicsView::scene() before accessing/using it. Most likely your app crashes because you get a nullpointer back.

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      1
      • F Offline
        F Offline
        Fidchells_Eye
        wrote on 24 Jun 2016, 15:15 last edited by
        #3

        Hey Joel

        Thanks the code lines:
        QGraphicsScene* scene = new QGraphicsScene(this);
        ui->GVpreview->setScene(scene);

        fixed the issue as I don't know how to do the scene view bit in the form editor.

        1 Reply Last reply
        0

        2/3

        24 Jun 2016, 15:01

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved