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. QT and Video Interfaces
Forum Updated to NodeBB v4.3 + New Features

QT and Video Interfaces

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 5 Posters 1.1k Views 2 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.
  • S Stevendragoes

    Hi All,

    I am developing a personal GUI project to integrate OPENCV with QT. I have successfully integrated using MinGW 7.3.0. My Current GUI looks like this.
    d01b7078-391d-48f6-a37c-5d4fcdcc3bfb-image.png

    I want to do Offline Loading Video and Online Camera Interfaces using two PushButtons.
    I followed this tutorial https://www.youtube.com/watch?v=ZoFm_Mznq1M
    I have created the FileDialog and it is working fine.
    However, I don't want to write "this" and take up the whole screen of my widget. Hence, I created a sizeable widget named "videoframe" (dotted blue rectangle)

    mainwindow.h

    class MainWindow : public QMainWindow
    {
        Q_OBJECT                                    
    
    public:
        QWidget* videoframe;
        Ui::MainWindow *ui;
        std::string path;
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
        QString qpath;
    
        QMediaPlayer* player;
        QVideoWidget* vw;
        QProgressBar* bar;
        QSlider* slider;
    
    private slots:
        void on_actionLoad_Video_triggered();
        void closeEvent(QCloseEvent *event);
        void on_actionPlay_triggered();
        void on_actionPause_triggered();
        void on_actionStop_triggered();
    
    private:
        QString filepath;
    };
    

    mainwindow.cpp

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        player = new QMediaPlayer(this);
        vw = new QVideoWidget(videoframe);
        //to fix the Forcefully exited
        //to fix the Video WIdget
        //To resize and put into the videoframe
    
        player->setVideoOutput(vw);
    
    }
    void MainWindow::on_actionLoad_Video_triggered()
    {
        QMessageBox::StandardButton loadBtn = QMessageBox::question( this, "MainWindow",tr("Load Video? \n"), QMessageBox::No | QMessageBox::Yes,QMessageBox::Yes);
        if (loadBtn == QMessageBox::Yes)
        {
            qpath = QFileDialog::getOpenFileName(this, "Load Video File"); //Input code to skip the event when cancel is pressed
            if (qpath.isNull())
            {
                ui->textEdit->append("Cannot get file, user cancelled while choosing file");
            }
            else
            {
                path = qpath.toLocal8Bit().constData();
                cShowVideo(ui, path, qpath);                        //For OPENCV analysis and filtering
                on_actionStop_triggered();                          //Stop the Video
                player->setMedia(QUrl::fromLocalFile(qpath));       //Set the Media
                on_actionPlay_triggered();                          //Play the Media
            }
        }
        else
        {
            ui->textEdit->setText("User Cancelled");
        }
    }
    

    however, when i try to run the program,

    it gives me this error. which means that I failed to cast the video widget into the Qwidget frame? My main motive is to load the video into the QWidget named 'videoframe'.

    Any idea how to do so? Appreciate your help.

    Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by
    #6
    This post is deleted!
    1 Reply Last reply
    0
    • mranger90M mranger90

      Does it crash when executing inside of QtCreator or outside ?
      If it crashes inside of QtCreator than check the stack trace.
      If it crashes outside of QtCreator than you need to do a deploy.

      S Offline
      S Offline
      Stevendragoes
      wrote on last edited by
      #7

      @mranger90 said in QT and Video Interfaces:

      Does it crash when executing inside of QtCreator or outside ?
      If it crashes inside of QtCreator than check the stack trace.
      If it crashes outside of QtCreator than you need to do a deploy.

      Hi @mranger90 it crashed inside the QT Creator when I try to press the run button

      1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Seems to be a dangling pointer maybe ?
        You have
        QWidget* videoframe;

        which you never set to anything in the code shown.

        You show an ui file so i wonder if you mean

        ui->videoframe
        instead ?

        To use the one you have placed on the UI and not the one you have manually added.

        S Offline
        S Offline
        Stevendragoes
        wrote on last edited by
        #8

        @mrjj said in QT and Video Interfaces:

        Hi
        Seems to be a dangling pointer maybe ?
        You have
        QWidget* videoframe;

        which you never set to anything in the code shown.

        You show an ui file so i wonder if you mean

        ui->videoframe
        instead ?

        To use the one you have placed on the UI and not the one you have manually added.

        @mrjj yea I want to use the QVideoWidget inside the "videoframe" Qwidget that is created in the Ui shown in dotted rectangle in the UI screen shot. However I don't know how to use link it all together, is it ui->videoframe like you mentioned?

        1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          Seems to be a dangling pointer maybe ?
          You have
          QWidget* videoframe;

          which you never set to anything in the code shown.

          You show an ui file so i wonder if you mean

          ui->videoframe
          instead ?

          To use the one you have placed on the UI and not the one you have manually added.

          S Offline
          S Offline
          Stevendragoes
          wrote on last edited by
          #9

          @mrjj So should. It be

          vw = new QVideoWidget (ui->videoframe)
          Instead of

          vw= new QVideoWidget(videoframe)?

          mrjjM 1 Reply Last reply
          0
          • S Stevendragoes

            @mrjj So should. It be

            vw = new QVideoWidget (ui->videoframe)
            Instead of

            vw= new QVideoWidget(videoframe)?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #10

            @Stevendragoes
            Hi
            Yes as the UI hold the widgets you put in visually and
            the other one seems like a dangling pointer which will crash.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Stevendragoes
              wrote on last edited by
              #11

              Hello @mrjj

              I have done the necessary changes. However, the video is not showing in the rectangle frame that I have drawn.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Stevendragoes
                wrote on last edited by
                #12

                Hello @jsulm @mrjj

                I have typed in according to what you have mentioned

                MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                    , ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                    player = new QMediaPlayer(ui->videowidget);
                    vw = new QVideoWidget(ui->videowidget);
                    player->setVideoOutput(vw);
                }
                
                

                However, the video does not load when I loaded the video. I have the text box to check the file path. the file path is fine. However, the video could not be displayed in the custom rectangle box that I drew.
                e0ca49fd-8dec-4c34-9e13-a34c8d9e62ad-image.png

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Stevendragoes
                  wrote on last edited by
                  #13

                  Hello @jsulm and @mrjj

                  After trying out and researching, I found a lazy man's way of showing in the UI, could be called my first draft.

                  MainWindow::MainWindow(QWidget *parent)
                      : QMainWindow(parent)
                      , ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                      player = new QMediaPlayer(this);
                      vw = new QVideoWidget(this);
                      player->setVideoOutput(vw);
                      vw->setGeometry(30,140,800,600);
                      vw->show();
                  }
                  
                  

                  However, I want to cast into the grid layout as the result wasn't up to my expectations.. I want the videoframe to resize when the window resizes.. Any Idea how? I didn't use the QWidget to load the video. If i were to use the QWidget to load the video, it will be good.

                  jsulmJ 1 Reply Last reply
                  0
                  • S Stevendragoes

                    Hello @jsulm and @mrjj

                    After trying out and researching, I found a lazy man's way of showing in the UI, could be called my first draft.

                    MainWindow::MainWindow(QWidget *parent)
                        : QMainWindow(parent)
                        , ui(new Ui::MainWindow)
                    {
                        ui->setupUi(this);
                        player = new QMediaPlayer(this);
                        vw = new QVideoWidget(this);
                        player->setVideoOutput(vw);
                        vw->setGeometry(30,140,800,600);
                        vw->show();
                    }
                    
                    

                    However, I want to cast into the grid layout as the result wasn't up to my expectations.. I want the videoframe to resize when the window resizes.. Any Idea how? I didn't use the QWidget to load the video. If i were to use the QWidget to load the video, it will be good.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    @Stevendragoes said in QT and Video Interfaces:

                    Any Idea how?

                    Well, put it into your layout.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    2
                    • S Offline
                      S Offline
                      Stevendragoes
                      wrote on last edited by
                      #15

                      Alright @jsulm I will go and learn about the layout and do some trial and errors. Any questions I will ask again. Thanks for assisting me

                      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