Qt OpenGLScene working example - qt

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.

Related

Qt6 circular gauge issue

I am developing a qml app in qt5 with circular gauge. I want to port application qt 6. But in qt 6 qtquick extras is missing, so circular gauge is not available. Is qt planning to make it available in next releases of qt6? What can I do instead of using circular gauge in qt6?
Is there anyone who knows about it?
As far as I know there are no plans yet to port it to Qt 6. You could create a suggestion on Jira to express your interest in having it.
The code is here and here if you want to try to port it yourself or just use parts of it (keeping in mind the license, which is LGPL).
As you stated in the question, CircularGauge is not available in Qt6. So what can you do?
As a minimal effort, you can substitute CircularGauge with a functional similar component, for instance, RangeSlider. Of course, a RangeSlider looks nothing like a CircularGauge, but, it will, at least, allow you to compile and run your application. It will give you an application to test whilst you decide your options.
Then, as others have stated, you need to spend more effort allocated to porting. If you refer to the source code of CircularGauge, you see that they're using Canvas with a custom onPaint implementation. You could do the same in your port, or, you can find an alternative, e.g. Shape with ShapePath, etc. These efforts are non-trivial, and it boils down to the level of effort you wish to invest.

How to find the source of a recursive rearrange in QML

I updated my QML application from Qt 5.12 to Qt 5.15.
My application loads its qml sources using the following code:
auto* engine = new QQmlApplicationEngine(this);
...
engine->load(QUrl("qrc:/main.qml"));
When engine->load is called, I now get the following warning, which was not there with Qt 5.12:
Qt Quick Layouts: Detected recursive rearrange. Aborting after two
iterations.
How can I find the source of this warning so I can fix my code?
Edit:
After two downvotes, I would like to clarify the intent of my question.
I have a very large application which is loading a big tree of qml files, with main.qml being the main Window. The warning that I posted comes from the Application output pane, without any hint to a source file location that caused the warning.
I am looking for a way to find the source file location that caused this kind of warning. I believe it is reasonable to ask how to achieve that, and I believe that this is a generic problem that will come up for many people who update their qml code to Qt 5.15. It's in the nature of such a issue that a self-contained example (like asked for in the comments) cannot be provided.
It's a totally reasonable ask - the warning is ambiguous so you'd have to post the entire codebase to get a minimum viable. Afaik there is no reasonable way to locate the offending bits programmatically but look for Layout components (RowLayout, ColumnLayout, GridLayout) nested inside the same kind of Layout component; these are the usual offenders. For instance:
ColumnLayout {
ColumnLayout {
id: childColumnLayout
// this is generally the cause of your grief
// changing the the child ColumnLayout to a Column usually fixes it for me
}
}

KDE Taskbar Progress

I am trying to show a progress in the taskbar of the plasma desktop using the KDE Frameworks. In short, it want to do the same thing as dolphin, when it copies files:
I'm kinda stuck, because I don't even know where to get started. The only thing I found that could be useful is KStatusBarJobTracker, but I don't know how to use it. I could not find any tutorials or examples how to do this.
So, after digging around, and thanks to the help of #leinir, I was able to find out the following:
Since Plasma 5.6 KDE supports the Unitiy DBus Launcher-API, which can be used, for example, to show progress
I found a post on AskUbuntu that explains how to use the API with Qt
The real problem is: This only works, if you have a valid desktop file in one of the standard locations! You need to pass the file as parameter of the DBus message to make it work.
Based on this information, I figured out how to use it and created a GitHub repository, that supports cross platform taskbar progress, and uses this API for the linux implementation.
However, here is how to do it anyways. It should work for KDE Plasma and the Unity desktop, maybe more (haven't tried any others):
Create a .desktop file for your application. For test purpose, this can be a "dummy" file, that could look like this:
[Desktop Entry]
Type=Application
Version=1.1
Name=MyApp
Exec=<path_to>/MyApp
Copy that file to ~/.local/share/applications/ (or wherever user specific desktop files go on your system)
In your code, all you need to do is execute the following code, to update the taskbar state:
auto message = QDBusMessage::createSignal(QStringLiteral("/com/example/MyApp"),
QStringLiteral("com.canonical.Unity.LauncherEntry"),
QStringLiteral("Update"));
//you don't always have to specify all parameters, just the ones you want to update
QVariantMap properties;
properties.insert(QStringLiteral("progress-visible"), true);// enable the progress
properties.insert(QStringLiteral("progress"), 0.5);// set the progress value (from 0.0 to 1.0)
properties.insert(QStringLiteral("count-visible"), true);// display the "counter badge"
properties.insert(QStringLiteral("count"), 42);// set the counter value
message << QStringLiteral("application://myapp.desktop") //assuming you named the desktop file "myapp.desktop"
<< properties;
QDBusConnection::sessionBus().send(message);
Compile and run your application. You don't have to start it via the desktop file, at least I did not need to. If you want to be sure your application is "connected" to that desktop file, just set a custom icon for the file. Your application should show that icon in the taskbar.
And thats basically it. Note: The system remembers the last state when restarting the application. Thus, you should reset all those parameters once when starting the application.
Right, so as it turns out you are right, there is not currently a tutorial for this. This reviewboard request, however, shows how it was implemented in KDevelop, and it should be possible for you to work it out through that :) https://git.reviewboard.kde.org/r/127050/
ps: that there is no tutorial now might be a nice way for you to hop in and help out, by writing a small, self contained tutorial for it... something i'm sure would be very much welcomed :)

How to Interact with a Qt C++ library inside a QML/QtQuick application?

I recently wrote a Qt based library to manage requests to TheMovieDB.org for a professional desktop application.
Not really experienced with QML and QtQuick, I think about migrating this application to QML which seems to be really adapted for.
I began few tutorials with QML...Amazing.
And now, I wonder if I can integrage my wrapper library into a QML application ?
Basically, let the user capture a movie name into a nice QML interface, froward the input parameters to the c++ wrapper, and retrieve the resulting json results + QPixmap object.
Is it something possible ? I found some piece of codes to access QML components from a Qt c++ application but the inverse yet.
Or maybe am I thinking the things the wrong way ?
Have you ever wrote something similar, I mean regarding the interaction mechanism?

Qt5, Phonon and Multimedia kit

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

Resources