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.
QtWS25 Last Chance

GraphicsView crash with GraphicsVideoItem.

Scheduled Pinned Locked Moved Solved General and Desktop
mediaplayergraphicviewqgraphicsvideoiform
3 Posts 2 Posters 1.5k Views
  • 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.
  • Fidchells_EyeF Offline
    Fidchells_EyeF Offline
    Fidchells_Eye
    wrote on 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.

    Joel BodenmannJ 1 Reply Last reply
    0
    • Fidchells_EyeF Fidchells_Eye

      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.

      Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on 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
      • Fidchells_EyeF Offline
        Fidchells_EyeF Offline
        Fidchells_Eye
        wrote on 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

        • Login

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