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();
}
转载于:https://www.cnblogs.com/lifan3a/articles/7285962.html
SDL如何嵌入到QT中?!相关推荐
- Qt中嵌入Directx11
最近要做个游戏场景编辑器,需要directx11配合gui框架使用,所以简单地弄了一个directx11嵌入到Qt窗体中的程序. 1 建立工程 建一个Qt的工程,配置好directx的包含目录和库目录 ...
- qt将html加载到资源文件,web页面嵌入到Qt
标签(空格分隔): plug 开发方式:在web环境下开发完成后,将单独页面嵌入到qt中,html.js等文件都作为资源加入到qt工程中 1):1.html页面中引入webchannel库: 其中,w ...
- Qt中嵌入web网页的几种实现方式
1.背景 Web网页的界面交互相比较Qt客户端而言有着比较大的优势:更加的多样化和更高的使用便捷性使得我们即使在客户端中也可以考虑将web网页嵌入到客户端的界面当中.如此便能将web的优势和客户端进行 ...
- 将外部exe嵌入到界面中(Windows)——Qt
前言 之前只做过,在界面中调起外部程序exe,只用将QProcess启动即可.如今,尝试将外部的exe嵌入到Qt的界面中,基本实现了,感觉挺神奇的! 效果图 我写了一个小demo,是通过菜单栏触发的 ...
- 将Unreal4打包后的工程嵌入到Qt或者桌面中
2019独角兽企业重金招聘Python工程师标准>>> 嵌入到Qt窗口有2种思路: 1.直接使用WinAPI将窗口直接嵌入,缺点:你需要自己编写移动.Layout之类的调整代码. 2 ...
- Qt中嵌入视频并循环播放方法
Qt中插入视频的方法很多,有QVideoPlayer方法,也有用Phonon的,本篇博客就是描述如何在一个QMainwindow界面中,划出一个区域,播放视频,并可以控制视频的切换.停止.暂停.循环, ...
- matplotlib嵌入到pyqt中
在pyqt5中使用matplotlib 前言 虽然,qt中也提供了绘图函数,但对于初学者并不是很容易掌握,众所周知,matplot提供了简单,易用,强大的绘图函数,结合mumpy基本可以达到matlb ...
- Qt中的QDialog
文章目录 1 Qt中的QDialog 1.1 QDialog简介 1.2 模态对话框和非模态对话框 1.3 对话框的返回值 2 登陆对话框实例分析 2.1 分析 2.2 代码实现 2.3 登录对话框的 ...
- QT中的模态对话框及非模态对话框
模态对话框(Modal Dialog)与非模态对话框(Modeless Dialog)的概念不是Qt所独有的,在各种不同的平台下都存在.又有叫法是称为模式对话框,无模式对话框等.所谓模态对话框就是在其 ...
- QT中QWidget、QDialog及QMainWindow的区别
QWidget类是所有用户界面对象的基类. 窗口部件是用户界面的一个基本单元:它从窗口系统接收鼠标.键盘和其它事件,并且在屏幕上绘制自己.每一个窗口部件都是矩形的,并且它们按Z轴顺序排列.一个窗口部件 ...
最新文章
- [Unity热更新]04.卸载方式
- C# SVN检出的代码,F12显示从元数据
- iis应用程序池不能启动
- 蓝桥杯-删除数组零元素(java)
- String s=a+b+c,到底创建了几个对象?
- 牛客练习赛52-记录
- python有什么用途视频_使用Python管理多平台视频流的最佳方法是什么?
- 笔记本电脑键盘切换_2019年最好的2500元以内的笔记本电脑
- Mac使用minicom串口工具
- Perl+批处理实现半自动批量生成动态通讯组
- 字体设计 css_设计好CSS字体堆栈的三个步骤
- cad2008安装教程_品茗BIM、平面图软件安装教程
- java 读取485_java通信 485
- 《评人工智能如何走向新阶段》后记(再续11)
- 操蛋 京东 配电脑 自助装机 严重问题
- 【分布式爬虫】Scrapy_redis原理分析并实现断点续爬
- 启用计算机的无线同屏,win10系统无线同屏功能如何使用
- 当前年的日历存储到数据库,用于判断某一天是假期还是工作日
- 使用cpolar发布群晖NAS上的网页 上篇(7.X版)
- 豆瓣评分9.0+,这几部纪录片看一部少一部!
热门文章
- 详述ArrayList类contains方法
- linux显示指定目录容量,linux 查看指定目录的容量大小,系统目录容量大小
- xml存储数据 优缺点_Python大神都是这样处理xml文件的!
- Race Condition是什么
- unable to remove repository reference (must force) - container is using its referenced image
- 基于SSM的健身俱乐部管理系统
- $(#).html(ftl) js 动态引入宏定义,FTL惯用标签及语法
- Android广播机制(2)
- java过滤集合,java – 如何通过交集过滤集合集合?
- Linux chapter test 9