I am using Qt5 and I found this example code , but I need to show video in some of available Qt visual objects, in which objects I can use this video overview code with VideoWidget? I am Qt beginner, and I am trying to understand how Qt works.
Thanks!
In C++, a QVideoWidget inherits from QWidget, you can put in a window or in another widget.
There's an example "videowidget" project in the Examples directory of the Qt sources.
A minimal exemple:
main.cpp
#include <QApplication>
#include <QMainWindow>
#include <QVideoWidget>
#include <QMediaPlayer>
#include <QMediaPlaylist>
int main(int argc, char * argv[])
{
QApplication testApp(argc, argv);
QMainWindow w;
QVideoWidget videoWidget(&w);
w.setCentralWidget(&videoWidget);
QMediaPlayer *player = new QMediaPlayer(&w);
player->setMedia( QUrl::fromLocalFile("E:\\big_buck_bunny.mp4") );
player->setVideoOutput(&videoWidget);
w.show();
player->play();
return testApp.exec();
}
test_video.pro:
QT += core gui widgets multimedia multimediawidgets
TARGET = test_video
TEMPLATE = app
SOURCES += main.cpp
Related
I'm a beginner in Qt, currently reading this : https://zetcode.com/gui/qt5/menusandtoolbars/
When I declare QActions in a QToolBar, the QPixmap objects (turned into QIcons) are not showing :
No icons, only text
However, the QPixmap images are actually showing when I declare a QMenu without the toolbar.
I am using Qt6 ; working on Fedora ; no warning shown on my compiler.
simple_menu.hpp
#ifndef SIMPLE_MENU_HPP
#define SIMPLE_MENU_HPP
#include <QMainWindow>
#include <QApplication>
class SimpleMenu : public QMainWindow
{
public:
SimpleMenu(QWidget *parent = nullptr);
};
#endif
simple_menu.cpp
#include "simple_menu.hpp"
#include <QMenu>
#include <QMenuBar>
#include <QToolBar>
#include <QIcon>
#include <QAction>
SimpleMenu::SimpleMenu(QWidget *parent)
: QMainWindow(parent)
{
QPixmap newpix("new.png");
QPixmap openpix("open.png");
QToolBar *toolbar = addToolBar("main toolbar");
toolbar->addAction(QIcon(newpix), "New File");
toolbar->addAction(QIcon(openpix), "Open File");
}
main.cpp
#include "simple_menu.hpp"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
SimpleMenu window;
window.resize(350, 250);
window.setWindowTitle("Tuto Toolbar");
window.show();
return app.exec();
}
Maybe the system cannot find your pictures. Please try to put the full file path (like :).
QPixmap newpix("c:\mydoc\pictures\new.png");
To check if the pictures are loaded, you can do something a bit different :
QPixmap newpix;
qDebug() << newpix.load("c:\mydoc\pictures\new.png");
the load method returns true or false in case of loading fail.
Anyway, if you want to embed your icons in the final EXE file, check the Qt resource system
It's a convenient system to achieve what you want to do, and to avoid dealing with storage paths on your local drives.
Good luck !
I'm trying to build a UI form and interface to it using the example from:
https://doc.qt.io/qt-5/designer-using-a-ui-file.html
#include "ui_item.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget widget;
Ui::Item ui;
ui.setupUi(&widget);
widget.show();
return app.exec();
}
However, it just doesn't work. In the line
ui.setupUi(&widget); I get the error:
invalid conversion from ‘QWidget*’ to ‘QFrame*’
Is there something I'm missing? The top-level widget in Ui::Item is a QFrame. I'm using Qt 5.12 and Qt-Creator 4.12.4.
The issue was that my UI top level was a QFrame and it needed to be a QWidget. For whatever reason, the UI file generated as a QFrame.
I have the following piece of code:
#include <QtWidgets/QtWidgets>
#include <QtMultimedia/QCamera>
#include <QtMultimedia/QMediaPlayer>
int main(int argc, char * argv[])
{
QApplication testQt(argc, argv);
QMainWindow w;
QWidget videoContainer(&w);
w.setCentralWidget(&videoContainer);
QVideoWidget videoWidget(&videoContainer);
QCamera cam(&w);
cam.setViewfinder(&videoWidget);
cam.start();
w.show();
return testQt.exec();
}
in which I am trying to create a main window, create a container widget to display video, create a videowidget in that container, and then finally set the viewfinder of the camera to that videowidget. However, when I try to do this I get the error
Variable has incomplete type 'QVideoWidget'
Why am I getting this error?
You need to include the corresponding header as follows:
#include <QVideoWidget>
You may also need to add this to your project file:
QT += multimediawidgets
In QT creator, I am developing a program in QT and need to include the following files:
QPtrList.h
QPtrQueue.h
QString.h
However these files do not seem to be present and I am getting this error:
Expected temeplate-name before '<' token
Is there anyway to add these files to my installation of QT?
Use QT4.8 or QT5 (5 is better)
QPtrList.h and QPtrQueue.h are not supported by QT4.8 and QT5.
Use #include <QList> instead of QPtrList.h
Use #include <QQueue> instead of QPtrQueue.h
Example "console" in QT5:
#include <QList>
#include <QQueue>
#include <QString>
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}
Pro file:
QT += core
QT -= gui
TARGET = untitled8
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
I would like to ask if you could help me with my app.
I have an application in C++ using Qt (and Qwt) in MCVS 2010. I want to open QDialog window with QwtPlot on button click from Main Window (QMainWindow). Here is some code:
MainWindow.cpp
void MainWindow::on_pushButton_1_clicked ()
{
Dialog_plot dp;
dp.setModal(true);
dp.exec();
}
Dialog_plot.cpp:
#include <qwt_plot.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_curve.h>
#include "Dialog_plot.h"
Dialog_plot::Dialog_plot(QWidget *parent)
{
plot = new QwtPlot();
//more code...
main.cpp:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
This code is compiling, but when I click on that pushbutton_1 in my application I'm getting error:
Must construct a QApplication before a QPaintDevice
I know that such error was discussed many times and I was reading a lot about it but I can't see solution for my problem.
One more thing I would like to mention - I have similar application with Qwt plot written by somebody else and his application compiles and works without any problems in my MCVS. I was trying to compare Linker/libraries included but it seems to be the same. So I guess there is a problem with my application, I just can't solve it. I really need some help!