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", 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;
}
-
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;
}
Hi @alone777, and welcome!
Which OS are you on? You could try calling
QWindow::fromWinId()
followed byQWidget::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.
-
Hi @alone777, and welcome!
Which OS are you on? You could try calling
QWindow::fromWinId()
followed byQWidget::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.