Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to embedded sdl window into qt widget

how to embedded sdl window into qt widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alone777
    wrote on last edited by
    #1

    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",
    	SDL_WINDOWPOS_UNDEFINED,
    	SDL_WINDOWPOS_UNDEFINED,
    	SCREEN_WIDTH,
    	SCREEN_HEIGHT,
    	SDL_WINDOW_SHOWN
    );
    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
    SDL_UpdateWindowSurface(window);
    
    //Wait two seconds
    SDL_Delay(2000);
    
    //Destroy window
    SDL_DestroyWindow(window);
    
    //Quit SDL subsystems
    SDL_Quit();
    
    return 1;
    

    }

    JKSHJ 1 Reply Last reply
    0
    • A alone777

      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",
      	SDL_WINDOWPOS_UNDEFINED,
      	SDL_WINDOWPOS_UNDEFINED,
      	SCREEN_WIDTH,
      	SCREEN_HEIGHT,
      	SDL_WINDOW_SHOWN
      );
      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
      SDL_UpdateWindowSurface(window);
      
      //Wait two seconds
      SDL_Delay(2000);
      
      //Destroy window
      SDL_DestroyWindow(window);
      
      //Quit SDL subsystems
      SDL_Quit();
      
      return 1;
      

      }

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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 https://bugreports.qt.io/browse/QTBUG-40320 for some example code and a list of potential issues.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      A 1 Reply Last reply
      4
      • JKSHJ JKSH

        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 https://bugreports.qt.io/browse/QTBUG-40320 for some example code and a list of potential issues.

        A Offline
        A Offline
        alone777
        wrote on last edited by
        #3

        @JKSH I'm using Windows 7 SP2, thanks

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alone777
          wrote on last edited by
          #4

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

          createWindowContainer

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

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved