I'm writing a Qt GUI Application, but there's a strange error i can't figure out;
Here's the whole code:
main.cpp
#include "LevelEditor.h"
int main(int argc, char* argv[])
{
LevelEditor editor(argc, argv);
editor.go();
return 0;
}
LevelEditor.h
#ifndef LEVELEDITOR_H
#define LEVELEDITOR_H
#include <QtGui>
class LevelEditor
{
public:
LevelEditor(int argc, char* argv[]);
~LevelEditor();
void go();
protected:
QApplication* app;
QMainWindow* main_window;
QMenuBar* menu_bar;
QStatusBar* status_bar;
QWidget* central;
QMenu* menu_entry[3];
QFrame* about_frame;
QList<QAction*> file_actions;
QList<QAction*> edit_actions;
QList<QAction*> help_actions;
private:
};
#endif // LEVELEDITOR_H
LevelEditor.cpp
#include "LevelEditor.h"
#include <QStatusBar>
LevelEditor::LevelEditor(int argc, char* argv[])
{
//initialise main objects
app = new QApplication(argc, argv);
main_window = new QMainWindow();
menu_bar = main_window->menuBar();
status_bar = main_window->statusBar();
central = main_window->centralWidget();
about_frame = new QFrame();
//initialise menu entries and actions
menu_entry[0] = new QMenu(); //file
menu_entry[1] = new QMenu(); //edit
menu_entry[2] = new QMenu(); //about
//creating and connecting events to action
menu_entry[0]->setTitle("File");
file_actions.append(new QAction("New", menu_entry[0]));
file_actions.append(new QAction("Open", menu_entry[0]));
file_actions.append(new QAction("Save", menu_entry[0]));
file_actions.append(new QAction("Quit", menu_entry[0]));
QObject::connect(file_actions.back(), SIGNAL(triggered()), app, SLOT(quit()));
QObject::connect(file_actions.back(), SIGNAL(hovered()), status_bar, SLOT(showMessage("Quit this App"));
menu_entry[0]->addActions(file_actions);
menu_bar->addMenu(menu_entry[0]);
//edit menu
menu_entry[1]->setTitle("Edit");
edit_actions.append(new QAction("Cut", menu_entry[1]));
edit_actions.append(new QAction("Copy", menu_entry[1]));
edit_actions.append(new QAction("Paste", menu_entry[1]));
menu_entry[1]->addActions(edit_actions);
menu_bar->addMenu(menu_entry[1]);
//help menu
help_actions.append(new QAction("About", menu_entry[2]));
QObject::connect(help_actions.back(), SIGNAL(triggered()), about_frame, SLOT(show()));
menu_entry[2]->setTitle("Help");
menu_entry[2]->addActions(help_actions);
menu_bar->addMenu(menu_entry[2]);
about_frame->resize(400,300);
}
LevelEditor::~LevelEditor()
{
//dtor
}
void LevelEditor::go()
{
//nothing
main_window->showMaximized();
menu_bar->show();
status_bar->show();
app->exec();
}
This code compiles fine without errors.
Anyway, the debug console gives me a warning
QObject::connect : NO such slot &QStatusBar::showMessage("Quit this App")
The problem seems related to this line:
QObject::connect(file_actions.back(), SIGNAL(hovered()), status_bar, SLOT(showMessage("Quit this App"));
I've searched in "QStatusBar.h" for the showMessage function and it is declared, but can't be called neither with "." nor "->" (even if it's public). Also tried this:
QObject::connect(file_actions.back(), SIGNAL(hovered()), status_bar, SLOT(showMessage("Quit this App", 0));
and this:
QObject::connect(file_actions.back(), SIGNAL(hovered()), status_bar, SLOT(QStatusBar::showMessage("Quit this App"));
But to no avail, it just won't recognise the function.
Am i missing something here?
Thanks in advance.
EDIT: Solved, i was taking the hard way to show a status text instead of using QAction::setStatusTip, my bad.
You can't connect a signal to a slot with different signature. And you are not even using the proper connect syntax. The SLOT part should be:
SLOT(showMessage(const QString &))
It's to tell the meta object system what type(s) of parameters to send to the slot, not what concrete data to send.
In your case, you can't connect a signal with no parameter to a slot that expects one. You can achieve that by connecting the signal to your own slot and then call QStatusBar::showMessage from there.
You could use QSignalMapper to do what you want:
QSignalMapper * mapper = new QSignalMapper(this);
QObject::connect(file_actions.back(), SIGNAL(hovered()), mapper, SLOT(map()));
mapper->setMapping(file_actions.back(), "Quit this app");
connect(mapper, SIGNAL(mapped(const QString &)), statusBar, SLOT(showMessage(const QString &));
Using QSignalMapper allows you, to simply add another "hovered" messages without creating new slots for each. Simply for all other cases just use:
mapper->setMapping(yourAction/Button/Whater, "Your status message");
QObject::connect(yourAction/Button/Whater, SIGNAL(hovered/Other signal()), mapper, SLOT(map()))
Related
I have a class called UserInterface. In this class there are different functions. build_start_screen() adds all the widgets (labels, buttons,...) for the initial startscreen. build_option_a_screen() removes everything from the startscreen and adds all the widgets needed for the screen when the users click on the button for option A, and so on. The class is stripped down for the sake of this question.
Now I have declared a button in build_start_screen() and connected it to a simple MessageBox.exec() so it should pop-up on click.
However, nothing happens when the button gets clicked.
What am I doing wrong? Has it something to do with the lifetime of variables expiring after the function finishes?
#include <QApplication>
#include <QPushButton>
#include <QAbstractButton>
#include <QLabel>
#include <QFont>
#include <QVBoxLayout>
#include <QMessageBox>
//Class handling all the UI in this Application
class UserInterface {
public:
//Build the initial UI the user sees
void build_start_screen(QWidget& window) {
//Make new QVBoxLayout for this startscreen UI
this->layout = new QVBoxLayout(&window);
//Test messagebox
QMessageBox msgBox;
msgBox.setText("Button test.");
//Button to go to Option A-screen
QPushButton* showMsgBox = new QPushButton("Show pop-up");
QAbstractButton::connect(showMsgBox, SIGNAL (clicked()), &window, SLOT (msgBox.exec()));
//Add labels and button to QVBoxLayout
layout->addWidget(showMsgBox);
}
private:
//Properties
QVBoxLayout* layout;
};
int main(int argc, char **argv) {
QApplication app (argc, argv);
//Initialize Window
QWidget Window;
Window.resize(400, 250);
//Create new UserInterface object
//This will allow us to create different user-interfaces
//depending on the function we call
UserInterface* ui = new UserInterface();
ui->build_start_screen(Window);
Window.show();
return app.exec();
}
And what if I'd like to do the same, but instead of calling a messageBox I'd like to call another function?
#include <QApplication>
#include <QPushButton>
#include <QAbstractButton>
#include <QLabel>
#include <QFont>
#include <QVBoxLayout>
#include <QMessageBox>
//Class handling all the UI in this Application
class UserInterface {
public:
//Build the initial UI the user sees
void build_start_screen(QWidget& window) {
//Make new QVBoxLayout for this startscreen UI
this->layout = new QVBoxLayout(&window);
//Test messagebox
QMessageBox msgBox;
msgBox.setText("Button test.");
//Button to go to Option A-screen
QPushButton* showMsgBox = new QPushButton("Show pop-up");
QAbstractButton::connect(showMsgBox, SIGNAL (clicked()), &window, SLOT (build_option_a_screen()));
//Add labels and button to QVBoxLayout
layout->addWidget(showMsgBox);
}
void build_option_a_screen(QWidget& window) {
//Do stuff here with window
//e.g
window.resize(500, 500);
}
private:
//Properties
QVBoxLayout* layout;
};
int main(int argc, char **argv) {
QApplication app (argc, argv);
//Initialize Window
QWidget Window;
Window.resize(400, 250);
//Create new UserInterface object
//This will allow us to create different user-interfaces
//depending on the function we call
UserInterface* ui = new UserInterface();
ui->build_start_screen(Window);
Window.show();
return app.exec();
}
Your code has 2 problems:
The window "object" does not have slot "msgBox.exec()" as pointed out by the error:
QObject::connect: No such slot QWidget::msgBox.exec() in ../main.cpp:23
Correcting the above, the solution would be:
QObject::connect(showMsgBox, &QPushButton::clicked, &msgBox, &QMessageBox::exec);
but now the problem is that "msgBox" is a local variable that will be destroyed and cannot be displayed.
So the solution is to make msgBox a member of the class or a pointer (in the case of the pointer you must manage the dynamic memory to avoid memory leaks):
//Class handling all the UI in this Application
class UserInterface {
public:
//Build the initial UI the user sees
void build_start_screen(QWidget& window) {
//Make new QVBoxLayout for this startscreen UI
this->layout = new QVBoxLayout(&window);
msgBox.setText("Button test.");
//Button to go to Option A-screen
QPushButton* showMsgBox = new QPushButton("Show pop-up");
QObject::connect(showMsgBox, &QPushButton::clicked, &msgBox, &QMessageBox::exec);
//Add labels and button to QVBoxLayout
layout->addWidget(showMsgBox);
}
private:
//Properties
QVBoxLayout* layout;
QMessageBox msgBox;
};
Plus:
It is recommended not to use the old connection syntax as it has limitations and hides the problems.
It is recommended not to use the old connection syntax as it has limitations and hides the problems.
If you want to connect to a method of some kind that is not a QObject (for example X as you want the OP) then the solution is to use a lambda method:
//Class handling all the UI in this Application
class UserInterface {
public:
//Build the initial UI the user sees
void build_start_screen(QWidget& window) {
//Make new QVBoxLayout for this startscreen UI
this->layout = new QVBoxLayout(&window);
//Button to go to Option A-screen
QPushButton* showMsgBox = new QPushButton("Show pop-up");
QObject::connect(showMsgBox, &QPushButton::clicked, [this, &window](){
build_option_a_screen(window);
});
//Add labels and button to QVBoxLayout
layout->addWidget(showMsgBox);
}
void build_option_a_screen(QWidget& window) {
//Do stuff here with window
//e.g
window.resize(500, 500);
}
private:
//Properties
QVBoxLayout* layout;
};
My task is to write an automated UI test for a software being developed. It happens so, that there are radiobuttons triggering a messagebox, which stops my automated test until I manually confirm it (pressing ENTER). The issue is that I do not know how I can call that newly summoned messagebox and then have it confirmed by QTest::keyClick(<object>, QtKey::Key_Enter); and have my automated test continue the run.
I am using QWidgets, QApplication, Q_OBJECT and QtTest.
I will provide a code similar to what I am working with:
void testui1(){
Form1* myform = new Form1();
myform->show();
QTest::mouseClick(myform->radioButton01, Qt::LeftButton, Qt::NoModifier, QPoint(), 100);
// Message box pops up and stops the operation until confirmed
QTest::mouseClick(myform->radioButton02, Qt::LeftButton, Qt::NoModifier, QPoint(), 100);
// again
...
}
How exactly can I script to confirm the message box automatically? The message box is only an [OK] type, so I don't need it to return whether I have pressed Yes or No. A QTest::keyClick(<target object>, Qt::Key_Enter) method needs to know to which object it should press enter to. I tried including myform into the object and it did not work. Googling I did not find the answer. I found the following result as not functioning for what I am looking for
QWidgetList allToplevelWidgets = QApplication::topLevelWidgets();
foreach (QWidget *w, allToplevelWidgets) {
if (w->inherits("QMessageBox")) {
QMessageBox *mb = qobject_cast<QMessageBox *>(w);
QTest::keyClick(mb, Qt::Key_Enter);
}
}
The problem is that once you've "clicked" on your radio button, which results in QMessageBox::exec being called, your code stops running until the user clicks on of the buttons.
You can simulate the user clicking a button by starting a timer before you click on the radio button.
In the callback function for the timer you can use QApplication::activeModalWidget() to obtain a pointer to the message box, and then just call close on it.
QTimer::singleShot(0, [=]()
{
QWidget* widget = QApplication::activeModalWidget();
if (widget)
widget->close();
});
If you want to press a specific key on the message box, you can use QCoreApplication::postEvent to post a key event to the message box
QTimer::singleShot(0, [=]()
{
int key = Qt::Key_Enter; // or whatever key you want
QWidget* widget = QApplication::activeModalWidget();
if (widget)
{
QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier);
QCoreApplication::postEvent(widget, event);
}
});
So in terms of how this ties into the sample code you gave:
void testui1()
{
Form1* myform = new Form1();
myform->show();
QTimer::singleShot(0, [=]()
{
QWidget* widget = QApplication::activeModalWidget();
if (widget)
widget->close();
else
QFAIL("no modal widget");
});
QTest::mouseClick(myform->radioButton01, Qt::LeftButton, Qt::NoModifier, QPoint(), 100);
}
A sample app putting all the above together:
#include <QApplication>
#include <QMainWindow>
#include <QHBoxLayout>
#include <QPushButton>
#include <QTimer>
#include <QMessageBox>
#include <iostream>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QMainWindow window;
QWidget widget;
window.setCentralWidget(&widget);
QHBoxLayout layout(&widget);
QPushButton btn("go");
layout.addWidget(&btn);
QObject::connect(&btn, &QPushButton::clicked, [&]()
{
QTimer::singleShot(0, [=]()
{
QWidget* widget = QApplication::activeModalWidget();
if (widget)
{
widget->close();
}
else
{
std::cout << "no active modal\n";
}
});
QMessageBox(
QMessageBox::Icon::Warning,
"Are you sure?",
"Are you sure?",
QMessageBox::Yes | QMessageBox::No,
&window).exec();
});
window.show();
return app.exec();
}
Clicking on Go will look like nothing is happening, as the QMessageBox is closed immediately.
To prove that the message box is shown and then closed you can increase the time in the call to QTimer::singleShot to a value such as 1000. Now it will show the message box for 1 second, and then it will be closed by the timer.
I'm using QFileDialog::getOpenFileName right now. However, as suggested in this article, this crashes when the main application closes while the dialog is open. You can see an example of how to reproduce the crash here:
int main(int argc, char **argv) {
QApplication application{argc, argv};
QMainWindow *main_window = new QMainWindow();
main_window->show();
QPushButton *button = new QPushButton("Press me");
main_window->setCentralWidget(button);
QObject::connect(button, &QPushButton::clicked, [main_window]() {
QTimer::singleShot(2000, [main_window]() { delete main_window; });
QFileDialog::getOpenFileName(main_window, "Close me fast or I will crash!");
});
application.exec();
return 0;
}
I can use QFileDialog with the normal constructor instead, as described here. However, then I don't seem to get the native windows file open dialog.
Is there a way to get a non crashing program and use the native Windows file open dialog through Qt?
If you close your main_window instead of deleting it, you won't get any crash.
By the way, you could check if there is any QFileDialog opened to avoid a wrong app exit.
In the next example, I'm closing the dialog, but you could implement another solution:
#include <QTimer>
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QFileDialog>
#include <QDebug>
int main(int argc, char **argv) {
QApplication application{argc, argv};
QMainWindow *main_window = new QMainWindow();
main_window->show();
QPushButton *button = new QPushButton("Press me");
main_window->setCentralWidget(button);
QObject::connect(button, &QPushButton::clicked, [main_window]() {
QTimer::singleShot(2000, [main_window]() {
QObjectList list = main_window->children();
while (!list.isEmpty())
{
QObject *object= list.takeFirst();
if (qobject_cast<QFileDialog*>(object))
{
qDebug() << object->objectName();
QFileDialog* fileDialog = qobject_cast<QFileDialog*>(object);
fileDialog->close();
}
}
main_window->close();
});
QFileDialog::getOpenFileName(main_window, "Close me fast or I will crash!");
});
application.exec();
return 0;
}
The design of your application is broken. The shut down of the application normally happens when the outernmost event loop in the main thread exists. This won't happen while a file dialog is active - by definition, its event loop is running then. Thus you're doing something you shouldn't be doing, and the file dialog is merely a scapegoat, or a canary in the coalmine indicating brokenness elsewhere.
I like to start out saying that I'm about as noob as they come. This is my first c++ program I built from scratch. I gotten most of the bugs ironed out, however I can't seem to be able to assign a value to a QLabel. I want the function 'value' to be called when the calculate button is pressed. The function 'value' should then do math and return the answer which is then assigned to the QLabel 'results'. Here is what I have so far.
#include <QApplication>
#include <QPushButton>
#include <QLabel>
#include <QSlider>
#include <QString>
#include <QSpinBox>
#include <QHBoxLayout>
#include <QComboBox>
double x;
double value(QSpinBox *spinner)
{
int speed;
speed = spinner->value();
x = speed/8;
return x;
}
int main(int argc, char *argv[])
{
QApplication prog(argc, argv);
QWidget *mainWindow = new QWidget;
mainWindow->setWindowTitle("Plex Calculator");
QPushButton *calculate = new QPushButton("Calculate");
QComboBox *kbormb = new QComboBox;
QSpinBox *spinner =new QSpinBox;
QSlider *slider = new QSlider(Qt::Horizontal);
QLabel *results = new QLabel;
spinner->setRange(1,1000);
slider->setRange(1,1000);
spinner->setValue(1);
QObject::connect(spinner, SIGNAL(valueChanged(int)),slider, SLOT(setValue(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)),spinner, SLOT(setValue(int)));
kbormb->addItem("kb/s");
kbormb->addItem("mb/s");
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(slider);
layout->addWidget(spinner);
layout->addWidget(kbormb);
layout->addWidget(calculate);
layout->addWidget(results);
QObject::connect(calculate, SIGNAL(clicked()), &prog, SLOT(results->setNum(value(*spinner));));
mainWindow->setLayout(layout);
mainWindow->show();
return prog.exec();
}
The issue is with following signal slot connection.
QObject::connect(calculate, SIGNAL(clicked()), &prog, SLOT(results->setNum(value(*spinner));));
You are trying to connect the clicked() signal of calculate button to results->setNum(value(*spinner)); slot of prog. But results->setNum(value(*spinner)); is not actually a slot.
A slot is simply a method in a class that inherits QObject. Method should be added under slots: section in the class. Read more about signals and slots here.
To fix this, you will have to create a separate class for your widget and add the logic their. you can add a slot to the newly created class and connect the clicked() signal to that. Then you can do the calculation in the slot.
Hey stackies currently trying to create some basic code that just plays a video file from local source (as trying to get that working then try and implement rtsp). below is my current code. If anyone can give me an idea where im going wrong that would be great.
Currently the code is failing with the error
C:\Qt\Qt5.1.0\5.1.0\msvc2010_opengl\examples\multimediawidgets\videographicsitem\main.cpp:58: error: C2664: 'QGraphicsScene::addItem' : cannot convert parameter 1 from 'QGraphicsVideoItem *' to 'QGraphicsItem *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
I presume I have to typecast the variable being inserted to additem. However have no idea how to do this with two Qclasses. If someone has an example of a basic player that just contains a video frame and plays the second you start the program ( not even a play button preferably). If anyone has anything like that please let me know as would make my life alot easier.
Main.cpp
#include "videoplayer.h"
#include <QApplication>
#include <QGraphicsView>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
//VideoPlayer player;
//QGraphicsView graphicsView;
QMediaPlayer *player ;
QGraphicsVideoItem *item;
QGraphicsView *graphicsView;
QGraphicsScene *scene;
player->setVideoOutput(item);
// scene->addItem(item);
graphicsView->scene()->addItem(item);
graphicsView->show();
player->setMedia(QUrl("rtsp://192.168.100.58:8554/stream"));
player->play();
graphicsView->show();
return app.exec();
}
Videoplayer.cpp
#include "videoplayer.h"
#include <QtWidgets>
#include <QVideoSurfaceFormat>
#include <QGraphicsVideoItem>
VideoPlayer::VideoPlayer(QWidget *parent)
: QWidget(parent)
, mediaPlayer(0, QMediaPlayer::VideoSurface)
, videoItem(0)
, playButton(0)
, positionSlider(0)
{
videoItem = new QGraphicsVideoItem;
videoItem->setSize(QSizeF(640, 480));
QGraphicsScene *scene = new QGraphicsScene(this);
QGraphicsView *graphicsView = new QGraphicsView(scene);
scene->addItem(videoItem);
QSlider *rotateSlider = new QSlider(Qt::Horizontal);
rotateSlider->setRange(-180, 180);
rotateSlider->setValue(0);
connect(rotateSlider, SIGNAL(valueChanged(int)),
this, SLOT(rotateVideo(int)));
QAbstractButton *openButton = new QPushButton(tr("Open..."));
connect(openButton, SIGNAL(clicked()), this, SLOT(openFile()));
playButton = new QPushButton;
playButton->setEnabled(false);
playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
connect(playButton, SIGNAL(clicked()),
this, SLOT(play()));
positionSlider = new QSlider(Qt::Horizontal);
positionSlider->setRange(0, 0);
connect(positionSlider, SIGNAL(sliderMoved(int)),
this, SLOT(setPosition(int)));
QBoxLayout *controlLayout = new QHBoxLayout;
controlLayout->setMargin(0);
controlLayout->addWidget(openButton);
controlLayout->addWidget(playButton);
controlLayout->addWidget(positionSlider);
QBoxLayout *layout = new QVBoxLayout;
layout->addWidget(graphicsView);
layout->addWidget(rotateSlider);
layout->addLayout(controlLayout);
setLayout(layout);
mediaPlayer.setVideoOutput(videoItem);
connect(&mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)),
this, SLOT(mediaStateChanged(QMediaPlayer::State)));
connect(&mediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
connect(&mediaPlayer, SIGNAL(durationChanged(qint64)), this, SLOT(durationChanged(qint64)));
}
VideoPlayer::~VideoPlayer()
{
}
void VideoPlayer::openFile()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"),QDir::homePath());
//QString fileName = "rtsp://192.168.100.58:8554/stream";
if (!fileName.isEmpty()) {
mediaPlayer.setMedia(QUrl::fromLocalFile(fileName));
playButton->setEnabled(true);
}
}
void VideoPlayer::play()
{
switch(mediaPlayer.state()) {
case QMediaPlayer::PlayingState:
mediaPlayer.pause();
break;
default:
mediaPlayer.play();
break;
}
}
Videoplayer.h
#ifndef VIDEOPLAYER_H
#define VIDEOPLAYER_H
#include <QMediaPlayer>
#include <QMovie>
#include <QWidget>
class QAbstractButton;
class QSlider;
class QGraphicsVideoItem;
class VideoPlayer : public QWidget
{
Q_OBJECT
public:
VideoPlayer(QWidget *parent = 0);
~VideoPlayer();
QSize sizeHint() const { return QSize(800, 600); }
public slots:
void openFile();
void play();
private slots:
void mediaStateChanged(QMediaPlayer::State state);
void positionChanged(qint64 position);
void durationChanged(qint64 duration);
void setPosition(int position);
void rotateVideo(int angle);
private:
QMediaPlayer mediaPlayer;
QGraphicsVideoItem *videoItem;
QAbstractButton *playButton;
QSlider *positionSlider;
};
#endif
.pro
TEMPLATE = app
TARGET = videographicsitem
QT += multimedia multimediawidgets
HEADERS += videoplayer.h
SOURCES += main.cpp \
videoplayer.cpp
target.path = $$[QT_INSTALL_EXAMPLES]/multimediawidgets/videographicsitem
INSTALLS += target
QT+=widgets
ALSO just tried this
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QMediaPlayer media;
const QString file = "C:/Users/nick.herniman/Downloads/big_buck_bunny_1080p_h264.mov";
QUrl url(QFileInfo(file).absoluteFilePath());
media.setMedia(url);
media.play();
return a.exec();
}
which works but only plays the audio of the file anyone know what im doing wrong here (does it need to be in a gui window or is it ok for me to just do it in a console application)?
There is nothing weird. :-)
It helps, when the compiler knows, that a QGraphicsVideoItem is a QGraphicsItem. And for the compiler to know this, #include <QGraphicsVideoItem> should be present.
I see, you have it in Videoplayer.cpp. But main.cpp sees only that there is a class QGraphicsVideoItem declared. You did a fine forward declaration. But what this class is... no way to know for the compiler in main.cpp. Add #include <QGraphicsVideoItem> to your main.cpp.
Try this simplest Example in Qt5:
QMediaPlayer *mediaPlayer = new QMediaPlayer(this, QMediaPlayer::VideoSurface);
QGraphicsVideoItem *videoItem = new QGraphicsVideoItem;
videoItem->setPos(100,100);
QGraphicsScene *scene = new QGraphicsScene(this);
ui->GV_VideoPlayer->setScene(scene);
scene->addItem(videoItem);
QString fileName = "/root/sampleVideos/videoplayback.mp4";
if(!fileName.isEmpty())
{
mediaPlayer->setMedia(QUrl::fromLocalFile(fileName));
}
mediaPlayer->play();
mediaPlayer->setVideoOutput(videoItem);
It is actually really weird that the QT documentation states a very similar example ( http://qt-project.org/doc/qt-5.0/qtmultimedia/qgraphicsvideoitem.html ), while the objects are actually not related. Apart from that, just looking through the QT documentation since I haven't worked with QT for a while - does creating a dummy QGraphicsItem, setting it as a parent to your QGraphicsVideoItem and then adding that dummy item to the scene help? I guess it would go something like this
QGraphicsItem* dummy = new QGraphicsItem;
item = new QGraphicsVideoItem(dummy);
graphicsView->scene()->addItem(dummy);