Qt5 - Porting a Video Player from 4.8 to 5.1 - c++

I'm working on migrating my code from Qt 4.8.4 to Qt 5.1.1 and seemed to have run into a peculiar problem. Previously I was using the Phonon library's video widget to allow users to interact with the video. Since Phonon is no longer supported I was looking for a way to replace my Phonon widget via the Qt Designer but I found no replacement widget available. Does anyone know how we're supposed to go about porting this functionality?
If anyone has any insight, it is appreciated as always!

All the other answers provide very useful information, but since I was looking for a specific and functional implementation, I'm guessing people that stumble on this may be looking for one as well, so I'll post my code along with my thought process and a bit of background info of my setup.
videoWidget = new QVideoWidget;
player = new QMediaPlayer;
verticalLayout->addWidget(videoWidget);
player->setVideoOutput(videoWidget);
player->setMedia(QUrl::fromLocalFile("Resources\\videos\\example.m4v"));
videoWidget->show();
player->play();
So to go through this, basically in my project I have a widget that is a part of a stackwidget structure on which I have some QWidgets like playback control buttons, labels, etc, and I previously had my Phonon video player. I really really didn't want to generate it all programatically so I managed to find a solution.
The above code was located in this container widgets constructor. In the designer I have made a simple, empty verticalLayout, positioned and sized it to my liking. This allowed me to embed the QVideoWidget despite not having a interactive QWidget in the Designer. videoWidget, and player are declared as private in the container widget's header file.

You've already noted there's no more Phonon
Now what you've got is QtMultimedia and the QtMultimediaWidgets. If you want them available to your project and you're using Qmake, then change your QT line in your .pro file from something like:
QT += widgets
to:
QT += widgets multimediawidgets
That won't do anything about the designer interaction, though. I think it's probably a matter of no one having done the work to make a custom widget extension for QVideoWidget.
If that's correct, then if you want to place a QVideoWidget into your form via Qt designer you will have to use "Widget Promotion". Just put an ordinary QWidget into your layout, and then right click on it in the form and pick Promote to ...
As for the specifics of porting Phonon abilities to the new widgets, I dunno what's covered and what isn't. No answers here yet, either:
How to port Qt4.6 Phonon based media-application to Qt 5.1?

It seems that although Qt itself no longer includes Phonon, there is a Qt5 port available as an external library:
http://community.kde.org/Phonon/Releases/Core/4.7.0
Alternatively, you can switch to the new QtMultimedia APIs:
https://qt-project.org/doc/qt-5.1/qtmultimedia/videooverview.html

Related

Unreal Engine 4 + Qt Widget

Working on project with UE4. I want to create UI with using Qt Designer and all Qt UI tools. I have already done opening window with some Qt forms (treeview and group of checkboxes) but I failed transmit picture from Unreal Engine window to QWidget.
I read about HWDL window, but i didn't found any information about realization. Found only how to get HWDL from UE4, but didn't found how to set to QWidget or wise versa get HWDL from QWidget and set it for UE4 (I think the second one better).
Maybe someone have done it? Or know approach to do it.

Qt - Display animated GIF selected by QListWidget on MainWindow

thank you in advance for reading and help.
I'm trying to make a GIF manager based on a QListWidget where you can select a GIF from the list (using on_*_itemClicked, as you can see below) and it will appear the animated GIF in the space below the list (or sideways, doesn't matter).
void MainWindow::on_listOfURL_itemClicked(QListWidgetItem *item)
{
QLabel* lab = new QLabel(this);
QMovie* mov = new QMovie(":/res/giftest/C:/Users/Rober/Desktop/giftest.gif");
lab->setGeometry(200, 200, 200, 200);
lab->setMovie(mov);
lab->show();
mov->start();
}
GUI screenshot of the program
I've tried using the piece of code above, but it shows nothing. It is just a futile try of making it work, that's why the GIF path is the same, you needn't worry about it.
Honestly, I've search a lot of code in forums and this very website regarding GIFS and animations, and none of the things I've seen have worked for me.
How should I proceed? I guess I should use some graphics QWidget in the UI and link it with the function on_*_itemClicked so it takes the location of the image from the QListWidgetItem and displays where I pointed in the UI.
I've gotten the code pasted here by surfing the Mighty Google, and it brings me some doubts:
I create a QLabel with the MainWindow as parent. Okay, but where will it appear?
Can't I create in the Designer a widget that I can define where will it be and just make the GIF work?
I think I've explained myself correctly, if not just let me know.
EDIT: I think what I need is a QLabel that is inside the MainWindow, below the URL list. How do I shape that QLabel in QtDesigner and then take that same QLabel in code and manipulate it with the GIF?
I think, you need to include into .pro
QTPLUGIN += qgif
and show label->show();
Of course you can add things in designer. You can add custom widgets you create, but you need make special project that would make a "plugin" for Designer and build it in Release mode, then install plugin in proper plugin folder.
For that you should be sure, that those are added to .pro file:
CONFIG += plugin
TEMPLATE = lib
QT += widgets uiplugin
Then you need to declare and implement plugin derived from QObject AND QDesignerCustomWidgetInterface.
DO CHECK validity: mov->isValid() Code that relies on external sources being good eventually becomes source of little disasters. Program either need a plugin's .dll next to it or static plugin linked with it
When you installed Qt, you installed app called QtAssistant. Take advantage of it. It's great deal of help. as well as their forums and examples storage you got in Qt directory. Qt5 got plugin example online: http://doc.qt.io/qt-5/qtwidgets-tutorials-widgets-childwidget-example.html
Okay, I've found myself the answer. It was pretty silly actually:
I didn't realize I could select a QLabel created in QtDesigner using ui->label and manipulate it.
ui->label->setMovie(selectedGif);
selectedGif->start();
ui->label->show();
Novice mistakes...

QT widgets vs QT GUI

I'm new at QT, actually I didn't start yet but I'm intending to create a xml file (markups and nodes and everything .. ) from a QT user interface.
For example the user can find in my interface text fields where he can insert an employee name, id and age and my program will turn that to an employee node in my output xml file with its attributes name , id , age. so since I'm coding with c++ I wanted to create this interface as a QT GUI but I found that QT creator provides a project named QT Widget with the same option.
So I'm kind of confused now and I don't know what's the difference between them so I can chose.
I will appreciate any help from guys.
If I have understood your question correctly: a Qt Widget is a tiny element, one of the many items in a gui (buttons, comboboxes are all widgets). The Qt Widget, project type is for creating one, which you can use in a separate projects interface.
A Qt Gui is more likely the project type you want, that will allow you to drag in many widgets to create your 'interface text fields'.
You would use a Qt Widget project type if you need to do more advanced customization or create your own text field control.
Do you mean Qt Quick vs. Qt Widgets?
Qt Quick is a more recent type of Qt GUI which is created from a declarative markup languages known as QML. The QML source is interpreted at run-time as opposed to Qt Widgets which are compiled from C++ source code into native executable code. In addition to QML, Qt Quick uses inline Javascript for scripting the UI, but it can be (and usually is) interfaced from C++ for more complex processing.
EDIT: Qt Quick is also very much touch-oriented (at least at its current state) whereas Qt Widget GUIs provide a much richer set of UI elements. So if you are making a desktop application, you might want to leave Qt Quick alone.

How to develop new Qt GUI controls?

There are some Qt controls like QButton, QLabel etc.
Can I develop new Qt GUI control, for example QAccordion or QRibbon control?
How is this done, and from where can I read and learn about it?
You can create your own widgets by subclassing QWidget or existing QWidget subclasses, (e.g., QFrame)
Honestly, at this stage, though, I recommend familiarizing yourself with how Qt works before trying to create entirely new widgets. There are several books about Qt, my favorite of which is this one, which, among other things, shows you how to create your own widgets.
Can i develop new
Yes.
how to develop new own qt gui controls?
where can i read and learn it?
You should read qt documentation. Documentation is quite good, so there's no excuse for not reading it.
Analog clock example shows how to create custom widget.
And here you can see how-to use it qtdesigner http://doc.qt.io/qt-4.8/designer-creating-custom-widgets.html

Implementing drag and drop with QT 4.5 using QT Creator environment

We're about to commit to Qt and C++ (sigh) to do some cross-platform development. The latest version of Qt 4.5 seems very nice as does the QT Creator IDE, which although simple compared to other IDEs, is a good way to get started.
I'm trying to understand how to do drag and drop into QT widgets from the "outside" world. As far as I can tell from the documentation, you're supposed to subclass a widget that you want to have respond to drop events and override some methods (the dragEnterEvent and dropEvent member functions) for that widget.
But if I use the Qt Creator tool, I don't seem to have any access to the classes of the widgets that I have created using the GUI form builder and so I can't subclass them.
WHat's the secret?
Thanks in advance,
D
Someone on my team figured it out ---- turns out there is an option to "Promote" a widget, meaning you can subclass it to something else and then override the needed methods with no pain.
Seems to me it would have been more obvious if it said "Subclass widget..." rather than "Promote" but that's OK.
This QT Creator is a very nice piece of work.
I've never used QT creator environment, but I assume it spits out code afterward. Can you edit the code it spits out?
If you subclass the classes in a separate file, it shouldn't get overwritten when you rebuild your app with QT creator environment.
I suppose this is really a question for the QT creator forum though, sounds like a problem in THEIR user interface.