Help with SDL inside QT

I know there’s a lot of messages about the topic and this is my first
e-mail to the list so I’m really embarrassed, but I have to ask. I’m
desperate.

I’m trying to use SDL to update a Qt widget. So i tried the window id
hack, but I wasn’t successfull and I can’t find help anywhere. What I did:

  1. made the qwidget
  2. got its window id (with the winId() method)
  3. used the id to set SDL_WINDOWID env variable
    4 tried to use SDL on that window.

The program, at the command

screen = SDL_SetVideoMode(640, 480, 24, SDL_SWSURFACE);

stops with:

X Error: BadWindow (invalid Window parameter) 3
Major opcode: 3
Resource id: 0x0
Fatal signal: Segmentation Fault (SDL Parachute Deployed)

What am I doing wrong?

Thanks in advance!

Cesar

“The following sentence is true.
The preceding sentence is false.”
– A strange loop

I’m trying to use SDL to update a Qt widget. So i tried the window id
hack, but I wasn’t successfull and I can’t find help anywhere. What I did:

  1. made the qwidget
  2. got its window id (with the winId() method)
  3. used the id to set SDL_WINDOWID env variable
    4 tried to use SDL on that window.

Since this is asked so often it qualifies as a FAQ, but nobody has ever
answered it, I took a crack at it myself with your steps as a starting
point (thanks!) :slight_smile:

And… I got it!
The attached archive builds a simple Qt application qtSDL, which creates an
SDL “screen” widget, and if sample.bmp resides in the current directory,
blits that to the center of the widget. This screen widget correctly handles
resizing, paint events, and drawing interactions with Qt. Note that SDL no
longer handles events for the screen at this point, so you’ll have to do all
your actions based on Qt signals.

I’ve only tested this with Qt 3.0 on X11.

If the attachment gets munged, you can find this at:
http://www.libsdl.org/cvs/qtSDL.tar.gz

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/octet-stream
Size: 3020 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030120/a9dded0e/attachment.obj

Many thanks,

I have also tried to do such a thing, but never managed to do it. It will
be really useful (at least for me !).

Julien> ----- Original Message -----

From: slouken@devolution.com (Sam Lantinga)
To:
Sent: Tuesday, January 21, 2003 8:01 AM
Subject: Re: [SDL] Help with SDL inside QT

I’m trying to use SDL to update a Qt widget. So i tried the window id
hack, but I wasn’t successfull and I can’t find help anywhere. What I
did:

  1. made the qwidget
  2. got its window id (with the winId() method)
  3. used the id to set SDL_WINDOWID env variable
    4 tried to use SDL on that window.

Since this is asked so often it qualifies as a FAQ, but nobody has ever
answered it, I took a crack at it myself with your steps as a starting
point (thanks!) :slight_smile:

And… I got it!
The attached archive builds a simple Qt application qtSDL, which creates
an
SDL “screen” widget, and if sample.bmp resides in the current directory,
blits that to the center of the widget. This screen widget correctly
handles
resizing, paint events, and drawing interactions with Qt. Note that SDL
no
longer handles events for the screen at this point, so you’ll have to do
all
your actions based on Qt signals.

I’ve only tested this with Qt 3.0 on X11.

If the attachment gets munged, you can find this at:
http://www.libsdl.org/cvs/qtSDL.tar.gz

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

That’s exactly what I was looking for. I was going to solve the problem
in another way but now i can do what i wanted in the first place.

Thanks a lot!

Sam Lantinga wrote:>>I’m trying to use SDL to update a Qt widget. So i tried the window id

hack, but I wasn’t successfull and I can’t find help anywhere. What I did:

  1. made the qwidget
  2. got its window id (with the winId() method)
  3. used the id to set SDL_WINDOWID env variable
    4 tried to use SDL on that window.

Since this is asked so often it qualifies as a FAQ, but nobody has ever
answered it, I took a crack at it myself with your steps as a starting
point (thanks!) :slight_smile:

And… I got it!
The attached archive builds a simple Qt application qtSDL, which creates an
SDL “screen” widget, and if sample.bmp resides in the current directory,
blits that to the center of the widget. This screen widget correctly handles
resizing, paint events, and drawing interactions with Qt. Note that SDL no
longer handles events for the screen at this point, so you’ll have to do all
your actions based on Qt signals.

I’ve only tested this with Qt 3.0 on X11.

If the attachment gets munged, you can find this at:
http://www.libsdl.org/cvs/qtSDL.tar.gz

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Thanks for the SDL and Qt example program! I was wondering though if there
was any chance of mixing this with full screen mode. I would love to be able
to use SDL for the low level graphics and its ability to toggle between full
screen and window mode and also to use Qt for the user interface code.

For example I want to have an application that can be full screen or not but
it also has to pop up screens for user input and configuration and the mix of
SDL and Qt would be great!–
Brad Pepers
@Brad_Pepers

Thanks for the SDL and Qt example program! I was wondering though if there
was any chance of mixing this with full screen mode. I would love to be able
to use SDL for the low level graphics and its ability to toggle between full
screen and window mode and also to use Qt for the user interface code.

Nope, I can’t think of any simple way to do that.
You might be able to convince Qt to use an existing SDL window as a toplevel
widget… ?

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Nope, I can’t think of any simple way to do that.
You might be able to convince Qt to use an existing SDL window as a
toplevel widget… ?

I think I can call create(wid, false, true) in a QWidget constructor to make
it use an existing window id. How do I get the window id from SDL though?

Of course this would likely all end up being really platform specific as well
which is something I want to ignore so perhaps its just best to figure out a
good SDL GUI library to use and dump Qt. But thought I’d see how far I can
get with mixing SDL and Qt!–
Brad Pepers
@Brad_Pepers

Nope, I can’t think of any simple way to do that.
You might be able to convince Qt to use an existing SDL window as a
toplevel widget… ?

I think I can call create(wid, false, true) in a QWidget constructor to make
it use an existing window id. How do I get the window id from SDL though?

Use the SDL_syswm.h interface. There’s some code in the FAQ which shows
how to get the SDL window id and move the X11 window around. Theoretically
you could use the same interface to get the Windows window HANDLE and do
the same thing there…

Of course this would likely all end up being really platform specific as well
which is something I want to ignore so perhaps its just best to figure out a
good SDL GUI library to use and dump Qt. But thought I’d see how far I can
get with mixing SDL and Qt!

I’ve heard good things about ParaGUI, available from the libraries page.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment