SDL如何嵌入到QT中?!
如下 人家的代码,可是我编译之后却不行
/****************************************************************************
** $Id: qt/SDLWidget.cpp 3.0.5 edited Oct 12 2001 $
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
#include "SDLWidget.h"
#if defined(Q_WS_X11)
#include <X11/Xlib.h>
#endif
QSDLScreenWidget::QSDLScreenWidget( QWidget *parent, const char *name ) :
QWidget(parent, name), screen(NULL)
{
atexit(SDL_Quit);
}
void QSDLScreenWidget::resizeEvent( QResizeEvent * )
{
char variable[64];
// We could get a resize event at any time, so clean previous mode
screen = NULL;
SDL_QuitSubSystem(SDL_INIT_VIDEO);
// Set the new video mode with the new window size
sprintf(variable, "SDL_WINDOWID=0x%lx", winId());
putenv(variable);
if ( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
return;
}
screen = SDL_SetVideoMode(width(), height(), 0, 0);
if ( ! screen ) {
fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
return;
}
}
void QSDLScreenWidget::paintEvent( QPaintEvent * )
{
#if defined(Q_WS_X11)
// Make sure we're not conflicting with drawing from the Qt library
XSync(QPaintDevice::x11Display(), FALSE);
#endif
if ( screen ) {
SDL_FillRect(screen, NULL, 0);
SDL_Surface *image = SDL_LoadBMP("sample.bmp");
if ( image ) {
SDL_Rect dst;
dst.x = (screen->w - image->w)/2;
dst.y = (screen->h - image->h)/2;
dst.w = image->w;
dst.h = image->h;
SDL_BlitSurface(image, NULL, screen, &dst);