Skip to content

Add qt6 demo#15847

Draft
madebr wants to merge 5 commits into
libsdl-org:mainfrom
madebr:add-qt6-demo
Draft

Add qt6 demo#15847
madebr wants to merge 5 commits into
libsdl-org:mainfrom
madebr:add-qt6-demo

Conversation

@madebr

@madebr madebr commented Jun 17, 2026

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Description

This is 99% copy-and-paste of the SDL demo project at https://github.com/slouken/SDL_Qt_Demo

I added argument parsing, and use it for overriding the SDL backend.

On (Fedora) Linux, the example currently only works with the x11 video driver.
Run testqt6 --platform xcb to use the x11 back-end.

Using --platform wayland or --platform wayland-egl fails with a SIGABORT.

Untested on Windows, apple and other platforms.

Existing Issue(s)

@Kontrabant

Copy link
Copy Markdown
Contributor

Just FYI, SDL+Qt interop on Wayland is possible. See the end of https://github.com/libsdl-org/SDL/blob/main/docs/README-wayland.md

@madebr

madebr commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Just FYI, SDL+Qt interop on Wayland is possible. See the end of https://github.com/libsdl-org/SDL/blob/main/docs/README-wayland.md

Thanks, setting the global wl_display property makes it render the expected green when using the vulkan renderer. The qt menus work, but do not show up.
The gpu renderer shows a window, but nothing gets rendered. Using the software and opengl renderer segfaults.

Is it possible to use the SDL wayland backend, wihout SDL in control of pumping events?
Or does it require a SDL3 backend for qt 😓 ?

@slouken

slouken commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Let's mark this draft until more kinks are worked out of the integration?

@Kontrabant

Kontrabant commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

For OpenGL, SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, true) must be set, so the backend attaches the appropriate EGL objects to the surface. Once that is set, the GL renderers work.

@madebr madebr marked this pull request as draft June 17, 2026 20:23
@Kontrabant

Kontrabant commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

The qt menus work, but do not show up.

They seem to work on my system?

Screenshot_20260617_163713

The gpu renderer shows a window, but nothing gets rendered.

I get a black window as well. Not sure what is going on here, but I suspect it's just something not being passed through or configured correctly if it works on the other renderers.

@madebr

madebr commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

For OpenGL, SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, true) must be set, so the backend attaches the appropriate EGL objects to the surface.

Indeed. This makes the vulkan, opengl and software renderer behave identical: the surface is colored green but the menu does not appear but is functional. The gpu renderer shows a transparent window with no menu, but the menu is also functional.

@Kontrabant

Copy link
Copy Markdown
Contributor

Ah, the issue with the GPU renderer is the window having the hidden flag set. Once that is gone, it works.

Comment thread test/qt6/main.cpp Outdated
MainWindow window;
window.show();

return app.exec();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return app.exec();
const int ret = app.exec();
SDL_Quit();
return ret;

Need to shut down SDL properly, or it can occasionally error on exit due to threads still running.

@Kontrabant

Copy link
Copy Markdown
Contributor

I'll have a couple of fixes for the main branch tomorrow that should clean up the other issues.

@slouken

slouken commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

@Kontrabant, the original demo has an issue where mouse down works, but mouse up doesn't get delivered on X11:
https://github.com/slouken/SDL_Qt_Demo

@madebr madebr force-pushed the add-qt6-demo branch 4 times, most recently from f35b5d8 to 8bbb840 Compare June 18, 2026 17:26
@madebr

madebr commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

The renderers now correctly work on wayland.

The opengles and opengles2 renderers fail, which is probably expected.
But changing to the gpu/opengl renderer after having selected opengles does not correctly resize the window.
e.g. change to opengles renderer -> resize window -> gpu renderer -> resize window

This is how the demo shows up for me in GNOME. The menu is functional, but not rendered each frame. Instead, I get a glitched surface. There is lots of flickering. The title bar is always rendered there.
Screenshot From 2026-06-18 19-29-12

@madebr madebr force-pushed the add-qt6-demo branch 2 times, most recently from 68867d8 to ab343af Compare June 18, 2026 18:47
@Kontrabant

Kontrabant commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

The opengles and opengles2 renderers fail, which is probably expected.

Those should work. The issue is when creating a window with the GL flag, then creating a GLES2 context, SDL wants to recreate the window, which fails since external windows can't be recreated. I think a special case for this particular path will work.

But changing to the gpu/opengl renderer after having selected opengles does not correctly resize the window.
e.g. change to opengles renderer -> resize window -> gpu renderer -> resize window

I don't think switching renderers on external windows is something that can be well supported. SDL destroys and recreates internally managed windows when switching renderers for a reason, and since this can't be done for external windows, it's going to be glitchy in some cases. I doubt this is something that most real world apps will be doing though.

@Kontrabant

Copy link
Copy Markdown
Contributor

gles and gles2 should be fixed after rebasing on main. Switching from a GL renderer to the GPU renderer is still broken, but I think that's due to something conflicting at the driver level.

@Kontrabant, the original demo has an issue where mouse down works, but mouse up doesn't get delivered on X11: https://github.com/slouken/SDL_Qt_Demo

It looks like XI_ButtonPress events are received on presses, but for releases, only XI_RawButtonRelease is arriving. Is Qt somehow eating or suppressing the standard button release events? Maybe starting a grab?

This is how the demo shows up for me in GNOME. The menu is functional, but not rendered each frame. Instead, I get a glitched surface. There is lots of flickering. The title bar is always rendered there.

I see the same on GNOME as well, but it's fine on KDE and Sway, so what's causing it is another mystery (maybe something related to dirty regions?)

Someone familiar with the internals of Qt might know what is going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants