Bonjour à tous,
Je suis en train de créer un éditeur pour mon petit projet de jeu, et pour cela j'ai voulu coupler SFML 2.0 avec Qt 5.0.1.
Seulement, j'ai déjà un problème de compilation avec un code qui devrait en théorie fonctionner:
QSFMLCanvas.hpp
#ifndef QSFMLCANVAS_HPP
#define QSFMLCANVAS_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <qwidget.h>
#include <qtimer.h>
////////////////////////////////////////////////////////////
/// QSFMLCanvas allows to run SFML in a Qt control
////////////////////////////////////////////////////////////
class QSFMLCanvas : public QWidget, public sf::RenderWindow
{
public :
////////////////////////////////////////////////////////////
/// Construct the QSFMLCanvas
///
/// \param Parent : Parent of the widget
/// \param Position : Position of the widget
/// \param Size : Size of the widget
/// \param FrameTime : Frame duration, in milliseconds (0 by default)
///
////////////////////////////////////////////////////////////
QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime = 0);
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
virtual ~QSFMLCanvas();
private :
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing initializations
///
////////////////////////////////////////////////////////////
virtual void onInit();
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing its update and drawing stuff
///
////////////////////////////////////////////////////////////
virtual void onUpdate();
////////////////////////////////////////////////////////////
/// Return the paint engine used by the widget to draw itself
///
////////////////////////////////////////////////////////////
virtual QPaintEngine* paintEngine() const;
////////////////////////////////////////////////////////////
/// Called when the widget is shown ;
/// we use it to initialize our SFML window
///
////////////////////////////////////////////////////////////
virtual void showEvent(QShowEvent*);
////////////////////////////////////////////////////////////
/// Called when the widget needs to be painted ;
/// we use it to display a new frame
///
////////////////////////////////////////////////////////////
virtual void paintEvent(QPaintEvent*);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
QTimer myTimer; ///< Timer used to update the view
bool myInitialized; ///< Tell whether the SFML window has been initialized or not
};
#endif // QSFMLCANVAS_HPP
QSFMLCanvas.cpp
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include "QSFMLCanvas.hpp"
// Platform-specific headers
#ifdef Q_WS_X11
#include <Qt/qx11info_x11.h>
#include <X11/Xlib.h>
#endif
////////////////////////////////////////////////////////////
/// Construct the QSFMLCanvas
////////////////////////////////////////////////////////////
QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) :
QWidget (Parent),
myInitialized (false)
{
// Setup some states to allow direct rendering into the widget
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_NoSystemBackground);
// Set strong focus to enable keyboard events to be received
setFocusPolicy(Qt::StrongFocus);
// Setup the widget geometry
move(Position);
resize(Size);
// Setup the timer
myTimer.setInterval(FrameTime);
}
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
QSFMLCanvas::~QSFMLCanvas()
{
// Nothing to do...
}
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing initializations
////////////////////////////////////////////////////////////
void QSFMLCanvas::onInit()
{
// Nothing to do by default...
}
////////////////////////////////////////////////////////////
/// Notification for the derived class that moment is good
/// for doing its update and drawing stuff
////////////////////////////////////////////////////////////
void QSFMLCanvas::onUpdate()
{
// Nothing to do by default...
}
////////////////////////////////////////////////////////////
/// Return the paint engine used by the widget to draw itself
////////////////////////////////////////////////////////////
QPaintEngine* QSFMLCanvas::paintEngine() const
{
return 0;
}
////////////////////////////////////////////////////////////
/// Called when the widget is shown ;
/// we use it to initialize our SFML window
////////////////////////////////////////////////////////////
void QSFMLCanvas::showEvent(QShowEvent*)
{
if (!myInitialized)
{
// Under X11, we need to flush the commands sent to the server to ensure that
// SFML will get an updated view of the windows
#ifdef Q_WS_X11
XFlush(QX11Info::display());
#endif
// Create the SFML window with the widget handle
// The qualification is needed because QWidget::create also exists
RenderWindow::create(winId());
// Let the derived class do its specific stuff
onInit();
// Setup the timer to trigger a refresh at specified framerate
connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint()));
myTimer.start();
myInitialized = true;
}
}
////////////////////////////////////////////////////////////
/// Called when the widget needs to be painted ;
/// we use it to display a new frame
////////////////////////////////////////////////////////////
void QSFMLCanvas::paintEvent(QPaintEvent*)
{
// Let the derived class do its specific stuff
onUpdate();
// Display on screen
display();
}
Avec ce code le charmant compilateur me transmet ce message, tout en finesse:
11:01:04: Exécution des étapes pour le projet AAAAAAEditor...
11:01:04: Configuration inchangée, étape QMake sautée.
11:01:04: Débute : "D:\Qt\Tools\MinGW\bin\mingw32-make.exe"
D:/Qt/Tools/MinGW/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'D:/ProjetsC++/AAAAAAEditor-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug'
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT_OPENGL_ES_2_ANGLE -DQT_NEEDS_QMAIN -I..\AAAAAAEditor -I"C:\SFML\SFML-2.0\include" -I"..\..\Qt\5.0.1\mingw47_32\include" -I"..\..\Qt\5.0.1\mingw47_32\include\QtWidgets" -I"..\..\Qt\5.0.1\mingw47_32\include\QtGui" -I"..\..\Qt\5.0.1\mingw47_32\include\QtCore" -I"debug" -I"." -I"." -I"..\..\Qt\5.0.1\mingw47_32\mkspecs\win32-g++" -o debug\QSFMLCanvas.o ..\AAAAAAEditor\QSFMLCanvas.cpp
..\AAAAAAEditor\QSFMLCanvas.cpp: In member function 'virtual void QSFMLCanvas::showEvent(QShowEvent*)':
..\AAAAAAEditor\QSFMLCanvas.cpp:91:37: error: invalid conversion from 'WId {aka unsigned int}' to 'sf::WindowHandle {aka HWND__*}' [-fpermissive]
In file included from C:\SFML\SFML-2.0\include/SFML/Window.hpp:40:0,
from C:\SFML\SFML-2.0\include/SFML/Graphics.hpp:32,
from ..\AAAAAAEditor\QSFMLCanvas.hpp:7,
from ..\AAAAAAEditor\QSFMLCanvas.cpp:4:
C:\SFML\SFML-2.0\include/SFML/Window/Window.hpp:141:10: error: initializing argument 1 of 'void sf::Window::create(sf::WindowHandle, const sf::ContextSettings&)' [-fpermissive]
Makefile.Debug:844: recipe for target 'debug/QSFMLCanvas.o' failed
mingw32-make[1]: *** [debug/QSFMLCanvas.o] Error 1
mingw32-make[1]: Leaving directory 'D:/ProjetsC++/AAAAAAEditor-build-Desktop_Qt_5_0_1_MinGW_32bit-Debug'
makefile:34: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2
11:01:07: Le processus "D:\Qt\Tools\MinGW\bin\mingw32-make.exe" s'est terminé avec le code 2.
Error while building/deploying project AAAAAAEditor (kit: Desktop Qt 5.0.1 MinGW 32bit)
Lors de l'exécution de l'étape "Make"
Voilà, il me semble que toutes les informations à ma connaissance sont là.
Est-ce que vous sauriez comment résoudre cette erreur?