Important: Please read the Qt Code of Conduct -

how to embedded sdl window into qt widget

  • I'm using SDL 2.0 to show a h.264 video frame. but when create the a new sdl window , the sdl window is shown in a seperate window. I want it to be embedded into my widget.
    how ? thanks!
    #include <SDL.h>
    #include <stdio.h>
    #include <stdlib.h>

    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;

    int main(int argc, char* args[])
    //The window we'll be rendering to
    SDL_Window* window = NULL;

    //The surface contained by the window
    SDL_Surface* screenSurface = NULL;
    //Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    	printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
    	return 0;
    //Create window
    window = SDL_CreateWindow("Hello SDL",
    if (window == NULL)
    	printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
    	return 0;
    //Get window surface
    screenSurface = SDL_GetWindowSurface(window);
    //Fill the surface green
    SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0x00, 0xff, 0x00));
    //Update the surface
    //Wait two seconds
    //Destroy window
    //Quit SDL subsystems
    return 1;


  • Moderators

    Hi @alone777, and welcome!

    Which OS are you on? You could try calling QWindow::fromWinId() followed by QWidget::createWindowContainer(), but be aware this scenario isn't very well-supported.

    See for some example code and a list of potential issues.

  • @JKSH I'm using Windows 7 SP2, thanks

  • @JKSH said in how to embedded sdl window into qt widget:


    I have resolved this problem using SDL_CreateWindowFrom, thank you for your answer.

Log in to reply