crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )


  Ответ в Как сделать связку QT3 с SDL?
Введите ваше имя
Подтвердите код

Введите в поле код из 6 символов, отображенных в виде изображения. Если вы не можете прочитать код с изображения, нажмите на изображение для генерации нового кода.
Теги
Выровнять по центру
Ссылка на тему
Ссылка на сообщение
Скрытый текст
Сокращение
Код с подсветкой
Offtopic
 
Удалить форматирование
Спец. элементы
Шрифт
Размер
 
Цвет шрифта
 
Отменить ввод
Вернуть ввод
Полужирный
Курсив
Подчеркнутый
 
 
Смайлики
Вставить изображение
Вставить адрес электронной почты
Цитата
Код
Раскрывающийся текст
 
Увеличить отступ
По левому краю
По центру
По правому краю
Вставить список
Вставить список

Опции сообщения
 Включить смайлы?
Иконки сообщения
(Опционально)
                                
                                
  [ Без иконки ]
 


Последние 10 сообщений [ в обратном порядке ]
ViGOur Дата 24.2.2008, 23:04
  Пример связки Qt 4.0.1 и SDL 1.2.8-08:
main.pro
TEMPLATE = app
LANGUAGE = C++
TARGET = qtSDL
PROJECTNAME = SPARTA Video Tracking Demo
CONFIG += qt thread warn_on debug

INCLUDEPATH += /usr/include/SDL

LIBS += -lSDL

SOURCES    = SDLWidget.cpp main.cpp

HEADERS = SDLWidget.h

main.cpp
/*
** 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 <QMainWindow>
#include <QDesktopWidget>

#include "SDLWidget.h"

int main(int argc, char **argv)
{
    QApplication
        app(argc,argv);
    QMainWindow
        mw;
    QSDLScreenWidget
        *sdlWidget = new QSDLScreenWidget(&mw);
    mw.setCentralWidget(sdlWidget);

    // Query the desktop to determine the size of the desktop and
    // to center the application when it opens.
    //
    int
        width = QApplication::desktop()->width(),
        height = QApplication::desktop()->height();

    mw.setGeometry((width - 800)/2, (height - 600)/2, 800, 600);
    mw.show();

    return app.exec();
}

SDLWidget.h
/*
** 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 <Qt>
#include <QWidget>

struct SDL_Surface;

class QSDLScreenWidget : public QWidget
{
    Q_OBJECT
public:
    QSDLScreenWidget(QWidget *parent=0, Qt::WFlags flags=0);

protected:
    void resizeEvent(QResizeEvent *);
    void paintEvent(QPaintEvent *);

private:
    SDL_Surface
        *screen;
};
#endif

SDLWidget.cpp
/*
** 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 <iostream>

#include <QX11Info>

#include <SDL.h>
#include "SDLWidget.h"

#ifdef Q_WS_X11
#include <X11/Xlib.h>
#endif

QSDLScreenWidget::QSDLScreenWidget(QWidget *parent, Qt::WFlags flags) :
    QWidget(parent, flags),
    screen(0)
{
    // Turn off double buffering for this widget. Double buffering
    // interferes with the ability for SDL to be properly displayed
    // on the QWidget.
    //
    setAttribute(Qt::WA_PaintOnScreen);
}

void QSDLScreenWidget::resizeEvent(QResizeEvent *)
{
    // We could get a resize event at any time, so clean previous mode.
    // You do this because if you don't you wind up with two windows
    // on the desktop: the Qt application and the SDL window. This keeps
    // the SDL region synchronized inside the Qt widget and the subsequent
    // application.
    //
    screen = 0;
    SDL_QuitSubSystem(SDL_INIT_VIDEO);

    // Set the new video mode with the new window size
    //
    char
        variable[64];
    sprintf(variable, "SDL_WINDOWID=0x%lx", winId());
    putenv(variable);

    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
    {
        std::cerr << "Unable to init SDL: " << SDL_GetError() << std::endl;
        return;
    }

    screen = SDL_SetVideoMode(width(), height(), 0, 0);

    if (!screen)
    {
        std::cerr << "Unable to set video mode: " << SDL_GetError() <<
            std::endl;
        return;
    }
}

void QSDLScreenWidget::paintEvent(QPaintEvent *)
{
#ifdef Q_WS_X11
    // Make sure we're not conflicting with drawing from the Qt library
    //
    XSync(QX11Info::display(), 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);
    }
}
Litkevich Yuriy Дата 24.2.2008, 11:38
  извини, возможно это покажется не умный совет, но посмтори статью про qmake и ее подраздел про файлы проекта, там упоминается подключение сторонних библиотек
dell Дата 24.2.2008, 3:11
  Программа должна быть написана на QT и местами должна использовать<SDL.h>

Как подключить библиотеки SDL к про файлу QT с последующей компиляцией в Linux (использую FC, ASPLinux)?
Как на виджете выводить графику (поверхности SDL)?

ЗЫ
Братцы помогите, кто чем может гуглю нечего не могу найти :(
Нужен пример ткните носом плиз.
Просмотр темы полностью (откроется в новом окне)
RSS Рейтинг@Mail.ru Текстовая версия Сейчас: 13.7.2025, 17:40