I'm using three different QGLWidgets in the same main thread, preferably rendered at 60fps but I cannot achieve more than 20fps. It seems that this is caused by Vsync as each widget probably tries to synchronize with the refresh rate independently and therefore they lock somehow. If I only use two widgets I achieve 30fps. Or if I fix the update rate of one widget to, let's say 10fps, I reach 25fps on the others (10+25+25=60). swapInterval()
always returns 0, independent of the value I set with setSwapInterval(int)
. Any ideas? Can I disable Vsync? Or might the problem be caused by something different?

- 767
- 1
- 10
- 23
-
Have you found a solution yet? – maddin45 Apr 02 '14 at 10:05
-
Unfortunately not. I kinda have an ugly workaround by simply hiding the widgets since I'm not always using all of them at the same time but of course that's not an acceptable solution. – Marc Apr 03 '14 at 10:55
-
Too bad, I would really like to know what the problem is. – maddin45 Apr 03 '14 at 16:51
2 Answers
It seems that its currently the bug from Qt 5.0 - https://bugreports.qt.io/browse/QTBUG-29073
Turning the Vsync off will solve the problem with dividing update rate between QGLWidgets, your graphics card will render to screen as fast as you tell it to or as fast as it can. But you must disable the VSync in graphics card settings. Just setting fmt.setSwapInterval(0) will do nothing.
Unfortunately another problem raises, if you are painting video that contains horizontal moves, tearing will appear.
Hopefully the Qt 5.3 shall fix this bug.

- 1,647
- 16
- 30

- 46
- 2
-
Thanks! For some mysterious reasons I have never thought of the possibility that disabling Vsync could actually be a graphics card setting - problem solved ;) – Marc May 20 '14 at 10:10
For those who are still struggling with this issue, my short answer is: before trying anything else: install Qt 5.4.
Longer answer:
I never had any issue to disable VSync with Qt 4.8.
Using Qt 5.3.1 (in Kubuntu 14.04 64bit), I have never been able to force my QGLWidget not to sync at VBlank, which means that swapBuffers() was blocking no matter what. I disabled VSync both in the "Desktop effect" panel and the NVidia control panel, and setSwapInterval(0) to no avail. Therefore my fps have always been clamped to 60fps/numOfQGLWidget (unless I used SingleBuffering, but the flickering was not tolerable in my applications). Using multi-threading, it should theoretically be possible to have VSync enabled (hence no tearing), and achieve 60fps for multiple QGLWidget, but I failed to have that working as well.
Today, I just installed Qt 5.4, and it magically solved the issue: I can successfully have a non-blocking swapBuffers(), as I used to in Qt 4.8. I think Qt 5.3 forced VSync somehow no matter what you driver settings were. But it is no longer the case in Qt 5.4, at least in my configuration. It seemed the Qt team did a lot of work to improve OpenGL for Qt 5.4 (notably, they introduced the QOpenGLWidget class), so my advice to anyone using OpenGL with Qt would be to make the update to Qt 5.4, it will likely make your life easier.

- 7,015
- 4
- 30
- 59
-
Any advice on how to implement vsync with QOpenGLWidget, I'm using QOpenGLWidget as the base class for my video rendering window, but I get tearing. – SPlatten Aug 14 '17 at 11:00
-
1@SPlatten In your main() function, before constructing your QApplication, construct a `QSurfaceFormat format`, set `format.setSwapInterval(0)`, then `QSurfaceFormat::setDefaultFormat(format)`. See http://doc.qt.io/qt-5/qsurfaceformat.html#setSwapInterval and http://doc.qt.io/qt-5/qsurfaceformat.html#setDefaultFormat . Hopefully, it should do the trick. Otherwise, you might need to look at your graphics driver settings, or OS / desktop environment, which may override these settings. Generally, it's hard to ensure that vsync will be enabled in a portable manner. – Boris Dalstein Aug 15 '17 at 07:36
-
1