SDL如何嵌入到QT中?!
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);
}
SDL_Flip(screen);
}
}
/****************************************************************************
** $Id: qt/SDLWidget.h 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.
**
*****************************************************************************/
#ifndef SDLWIDGET_H
#define SDLWIDGET_H
#include <qwidget.h>
struct SDL_Surface;
class QSDLScreenWidget : public QWidget
{
Q_OBJECT
public:
QSDLScreenWidget( QWidget *parent=0, const char *name=0 );
protected:
void resizeEvent( QResizeEvent * );
void paintEvent( QPaintEvent * );
private:
SDL_Surface *screen;
};
#endif
/****************************************************************************
** $Id: qt/main.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 <qapplication.h>
#include "SDLWidget.h"
/*
The program starts here.
*/
int main( int argc, char **argv )
{
QApplication a(argc,argv);
QSDLScreenWidget w;
a.setMainWidget( &w );
w.show();
return a.exec();
}
linux?qt?sdl
[解决办法]
直接用QImage显示图像就可好了,
[解决办法]
我自己写的 一个Qt调用SDL播放声音的例子
楼主可以参考下,希望对你有帮助:
http://blog.csdn.net/qq214517703/article/details/8677798
[解决办法]
编译之后怎么不行
说的没头没尾的