Qt5, Phonon and Multimedia kit - qt

I´m quite new to Qt development and I´m using Qt5 Beta1 on MacOSX.
For the last two days I´ve been reading the docs and looking for information about the different possibilities that I have in order to implement a widget that displays the frame of a video which corresponds to a concrete moment in time. A good old preview, in short.
First I thought that, since I did not need anything fancy, Phonon would be the right choice, as it´s called to be "on a higher level (than QTMultimedia) and in many cases more suitable for application developers." I read its documentation and even found some discussions that could help me starting, like this; http://www.qtcentre.org/threads/13221-QT-4-4-Phonon-Video-Rendering-a-single-frame. But then, when I tried to make something on my own, I realized that I did not have the Phonon library. Surprised from it, I research about Phonon and Qt5. And that´s when all the trouble began.
I started reading conversation such as this one: http://comments.gmane.org/gmane.comp.lib.qt.user/1581
or this one: http://comments.gmane.org/gmane.comp.lib.qt.devel/3905 or this other link: https://bugreports.qt.io/browse/QTBUG-26471. And I got really confused, without knowing if it was a good idea to download the Phonon library or it was not going to be supported on Qt5 after some time.
So I decided to go a step back and think again about using QTMultimedia instead of Phonon. I looked at their VideoWidget example http://doc.qt.io/qt-4.8/qt-multimedia-videowidget-example.html and when I tried to run it, it threw several errors (I´m posting just the beginning of the output):
In file included from ../VideoExample/videoplayer.cpp:43:
In file included from ../VideoExample/videowidget.h:44:
../VideoExample/videowidgetsurface.h:57:11: warning: 'VideoWidgetSurface::isFormatSupported' hides overloaded virtual function [-Woverloaded-virtual]
bool isFormatSupported(const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const;
^
../../Downloads/qt-everywhere-opensource-src-5.0.0-beta1/qtbase/include/QtMultimedia/../../../qtmultimedia/src/multimedia/video/qabstractvideosurface.h:78:18: note: hidden overloaded virtual function 'QAbstractVideoSurface::isFormatSupported' declared here
virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const;
^
../VideoExample/videoplayer.cpp:61:40: error: expected a type
QAbstractButton *openButton = new QPushButton(tr("Open..."));
^
../VideoExample/videoplayer.cpp:62:6: error: no matching member function for call to 'connect'
connect(openButton, SIGNAL(clicked()), this, SLOT(openFile()));
^~~~~~~
../../Downloads/qt-everywhere-opensource-src-5.0.0-beta1/qtbase/include/QtCore/../../src/corelib/kernel/qobject.h:211:36: note: candidate function not viable: cannot convert argument of incomplete type 'QAbstractButton *' to 'const QObject *'
static QMetaObject::Connection connect(const QObject *sender, const char *signal,
And this is the moment when I felt I was completely lost and wrote here :/
So my actual questions are:
Does anyone knows the actual state of Phonon and if it´s a good idea to use it for Qt5? Is so, what do I have to make it work? I guess I´m mixing concepts here, but I´m terribly lost between what belongs to Qt and what no, and what are the implications of both possibilities.
Any idea why the example from QTMultimedia does not work?
In general, thoughts about this topic would be greatly appreciated.

The Phonon framework seems not to be included at Qt 5 (Qt and Key Technologies).
The example you tested seems to work only with Qt 4.7, not Qt 5. The Qt 5.0 version can be found here. The Qt 5.1 version can be found here.

Try installing phonon development kit.
yum install phonon-devel

Related

QT for OpenglEs on Desktop

I have an existing project which uses openglEs library (libGLESv2.lib) on DESKTOP platform.
Now I want to use QT as its user interface by using QGLwidget. However after calling any OpenGL function in QGLwidget::initializeGL function I get Access violation executing location 0x00000000 error at the code below,
void MyGLWidget::initializeGL()
{
if (!context()->create())
throw std::exception("no context :)");
context()->makeCurrent();
glViewport(0, 0, 640, 480);
}
If I also include the library opengl32.lib then glviewport function works but when I hit to glGenFramebuffers then I get the same error.
Could you please let me know how can I configure my project to use QT with opengles on desktop platform.
If I also include the library opengl32.lib then glviewport function works but when I hit to glGenFramebuffers then I get the same error.
glViewport is a OpenGL function found in every OpenGL version and profile since version 1. As such it's immediately available simply by linking against the basic OpenGL interface library.
glGenFramebuffers is a function introduced only with OpenGL-3 (OpenGL-ES 2, BTW, OpenGL-ES is not natively supported on Windows) and before you can use it, you have to
check that it is actually supported
load the OpenGL context dependent function pointer at runtime into the variable symbol you're actually calling
Failing to do the second step will give you the error you encounter. Failing to do the first step you try to load it, but loading may fail leading to the same result as if you didn't do (2) at all.
Qt provides all the function loading checks and executions for you, so I suggest you use it: http://doc.qt.io/qt-4.8/qglfunctions.html
It's not perfect, but it gets the job done.
Update (from comments)
Most likely you already have some OpenGL loader library in your project, that actually resolves everything, but before using Qt you did properly initialize it. Now using Qt you've got a mix of statically resolved symbols through opengl32.lib and symbols provided by that loader, yet the loader is not initialized. Look through the code as it was before integrating Qt and look for some initializing call (called after creating the OpenGL context/window but before doing any OpenGL work).
My best guest would be, that the EGL bindings you use also implement the OpenGL-ES wrapper/loader. As I already explained, Windows doesn't natively support OpenGL-ES (only regular OpenGL) and some kind of compatibility layer is required. It is most likely this layer that's getting in your way now. The good news is, that since you're on Windows you can use regular native OpenGL-3 instead; for the most part OpenGL-ES is a subset of OpenGL-3. You'll still need to runtime load GL-3 functions, but as already said, Qt can do that for you.
What to do:
Replace all occurrences of #include <EGL/egl.h> with #include <GL/gl.h> – that should get rid of the symbol shadowing.
Next, for all classes in which use of OpenGL functions is made, add an inheritance of QGLFunctions so that in the classes' namespaces the dynamically loaded functions are used.
Note that every class that inherits QGLFunctions must be instanced only when the target OpenGL context is made current OR you call initializeFunctions on the instances from QGLWidget::initializeGL (or its derivatives). you have to do the function initialization once for each instance of the class inheriting QGLFunctions and the initialization function must be called when the OpenGL context that's to be used is currently active. Like I said, Qt's QGLFunctions is not perfect; if it were it would do the necessary function pointer loading on demand, cache the result and in case of a OpenGL context switch automatically reinitialize.

Arduino Due in Atmel Studio 6.1. without Visualmikro

I prefer the tutorial from http://www.engblaze.com/tutorial-using-atmel-studio-6-with-arduino-projects/ over Visualmikro because I love being able to jump inside the arduino functions and modify them without having to install any kind of plugin.
I tried compile my project following the tutorial but it won't work: "undefined reference to _sbrk". Which sounds like a really bad linker error to me?
I needed to adapt a few things because the tutorial was written for an older version of the IDE and is targeting AVRs and not SAMs:
GNU C++/Symbols
List item
F_CPU = 84000000L
ARDUINO=154
GNU C++/Directories
[...]\Arduino\hardware\arduino\sam\cores\arduino
[...]\Arduino\hardware\arduino\sam\variants\arduino_due_x (had to change this one)
[...]\Arduino\hardware\arduino\sam\system\libsam
ARM/GNU Linker/Libraries
libcoreDue.a (I added Due, to be able to identify the type of arduino)
libsam_sam3x8e_gcc_rel_a
as well as the paths to those two files.
Any idea what I could have missed?
Thank you so much!

Using QValidator in QCoreApplication

I want to use QValidator and its subclasses (QRegExpValidator, QIntValidator) in QCoreApplication, but get the following error: "QValidator: No such file or directory"
If I add in .pro file the following line: "QT += gui" - all works fine, but that is not a solution for me.
Is there any technique to use QValidator in QCoreApplications?
No, this is not possible. QValidator is part of the gui lib. I suppose the Qt devs thought that QValidator makes only sense with Qt's text input classes. I checked again, above statement is still true. However, I looked into the code, QValidator does not depend on any gui stuff. On first glance it seems to be rather stand-alone. So you might be able to copy qvalidator.cpp and qvalidator.h from the Qt sources into your sources, do a reasonable amount of adjusting, and integrate this into your code. It might be possible, I don't say it will be easy.

Qt OpenGLScene working example

I'm using an OpenGLScene as a wrapper of the openGL, and I've started with the most simple example of that I've found on the internet. I've just copied everything from the link where they have a zip.
I compiled and run the program, and apparently this warning is always coming up (in the drawbackground method):
if (painter->paintEngine()->type()
!= QPaintEngine::OpenGL) {
qWarning("OpenGLScene: drawBackground needs a "
"QGLWidget to be set as viewport on the "
"graphics view");
return;
Does anyone knows why (I'm on a Mac)? Does anyone has a more "stable" example? Is this warning relevant?
Basically, I would like to know why this warning is appearing, and how can I get rid of it...
I don't really know where to start. I've tried several simple things (making the QGLWidget current Context for instance), but I don't know enough Qt to understand the when and how is the drawbackground method called.
Qt OpenGLScene working example
"Boxes" demo in Qt 4. Launch qtdemo, select demonstration->boxes. Or read it all online. Either that or read documentation for overpainting, HelloGL or any other OpenGL example.
I'm trying to have a "wrapper" to OpenGL using Qt. Using Qt as GUI, and OpenGL as visualization
QGLWidget
Are you having OpenGL or OpenGL2?
Try this code
if (painter->paintEngine()->type() != QPaintEngine::OpenGL
|| painter->paintEngine()->type() != QPaintEngine::OpenGL2)
What are you trying to do ?
IIRC the qq26 example didn't work in 4.7 (haven't tested it in 4.8).
But overpainting QWidgets on top of an openGL scene was added to 4.8 ( http://qt-project.org/doc/qt-4.8/opengl-overpainting.html ) rather than the hack in that example
edit: Just using an opengl display in Qt is simple, just derive from a QWidget and implement initializeGL, resizeGL and paintGL. There are Qt functions to wrap textures, VBOs, PBOs and all the other opengl stuff. See the OpenGL examples in the distribution.
I've made a small minimal OpenGL+Qt which I think can answer the point:
I don't really know where to start. I've tried several simple things
(making the QGLWidget current Context for instance), but I don't know
enough Qt to understand the when and how is the drawbackground method
called.
I think it can help someone who was in the position I was when I asked this question.

Qt signal wrapped in an ifdef

My Qt project links to a library that is linux-only. When the project is run under linux, I wish to have a signal fired on an event using a type defined in that library. A complication that I have, though, is that the project must also build in Windows. Obviously, this signal and the slot catching it wouldn't exist in Windows, and that's fine. I am, however, finding issues with Qt's moc tool failing to recognize the existence of an #ifdef __linux__ around the code that emits the signal. My code looks like this:
[SomeFile.h]
#ifdef __linux__
signals:
void SomeSignal(SomeTypeDefinedInTheLinuxLibrary);
#endif
[SomeFile.cpp]
#ifdef __linux__
emit SomeSignal(someObject);
#endif
When I attempt to compile this with g++, I get the error:
SomeFile.cpp:(.text+0x858c): undefined reference to SomeFile::SomeSignal(SomeTypeDefinedInTheLinuxLibrary)
Any ideas how to get moc and #ifdefs to play well together?
A much better solution is to always provide the signal and just comment out the code that fires it on Windows. That way, the public API is the same on all platforms.
[EDIT] The moc tool is really dumb. It doesn't actually understand the code; instead it just reacts on certain patterns. That's why it ignores the #ifdef.
To solve the issue, wrap the type or use #ifndef __linux__ and define your own dummy type in there so it compiles on Windows. Since the signal won't be emitted on Windows, the slot will never be used so any type that makes the code compile should be fine.
With Qt 5.3 at least using Visual Studio, I am able to pass pre-processor macros to the moc tool. In order to make this work, I had to text edit my Visual Studio project file and manually add command line arguments for each file in order to hand the pre-processor arguments to the moc tool. You can use -D[Pre-Processor], i.e. -DSPECIAL_BUILD or -DSPECIAL_BUILD=1, and the moc compiler is smart enough to see the #if SPECIAL_BUILD checks in your code and not try to moc those parts.
Just search for "moc.exe" and add the appropriate parameters for each configuration.

Resources