Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Using SMFL for drawing into a Qt Widget  (Read 6016 times)

0 Members and 1 Guest are viewing this topic.

sb

  • Newbie
  • *
  • Posts: 22
    • View Profile
[SOLVED] Using SMFL for drawing into a Qt Widget
« on: October 19, 2015, 03:50:57 pm »
Hey there.

So I'm about to write an application using Qt Widgets and want to draw using SMFL 2.3.2. I'v stumbled upon

http://www.sfml-dev.org/tutorials/1.6/graphics-qt.php

but it seems to be a bit outdated. Apparently, the functions Create() and Display() were changed to lower-case. So after adjusting this, the compiler (MinGW) says that the reference to "create" is ambiguous, referencing the line "create(winId());" inside the function void QSFMLCanvas::showEvent(QShowEvent*).

I haven't used Qt before and only tried very basic things with SMFL, hence I do not know how to handle this.

I would be very grateful if someone could help me with this so I can actually begin with what I have in mind.
« Last Edit: October 20, 2015, 02:19:59 pm by sb »

sb

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Using SMFL for drawing into a Qt Widget
« Reply #1 on: October 20, 2015, 01:05:39 pm »
After finding the Post http://en.sfml-dev.org/forums/index.php?topic=13851.msg97124 I changed

create(winId());

to

sf::RenderWindow::create((sf::WindowHandle)winId());
 

and hence the ambiguity is gone. However, when building it now tells

undefined reference to to `vtable for QSMFLCanvas'
,

referencing line

myInitialized (false)

of

#include "qsmflcanvas.h"

QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) :
QWidget       (Parent),
myInitialized (false)
{

in the implementation of QSMFLCanvas as provided in http://www.sfml-dev.org/tutorials/1.6/graphics-qt.php .

Any ideas on this? The file qsmflcanvas.o seems to be built.

sb

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Using SMFL for drawing into a Qt Widget
« Reply #2 on: October 20, 2015, 02:18:48 pm »
Okay, it seems like I could fix it by implementing stubs for the virtual methods. Anyway, I suggest updating the tutorial I linked to in my post.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: [SOLVED] Using SMFL for drawing into a Qt Widget
« Reply #3 on: October 20, 2015, 06:08:26 pm »
Would be great if you could actually do it there: https://github.com/SFML/SFML/wiki  :)

Any material produced by the community is welcomed since we don't have time to do everything ourselves.
SFML / OS X developer

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Using SMFL for drawing into a Qt Widget
« Reply #4 on: October 21, 2015, 03:01:27 am »
Okay, it seems like I could fix it by implementing stubs for the virtual methods. Anyway, I suggest updating the tutorial I linked to in my post.

The tutorial you posted is from SFML 1.6 which is quite a few years old now. I agree with Hiura about adding/updating this on the wiki so that people (Such as myself) might take advantage of this.

sb

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: [SOLVED] Using SMFL for drawing into a Qt Widget
« Reply #5 on: October 21, 2015, 07:12:28 pm »
Is there a way of posting in the wiki without registering on GitHub?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: [SOLVED] Using SMFL for drawing into a Qt Widget
« Reply #6 on: October 21, 2015, 08:05:23 pm »
No, probably not. Is that an issue for you?
SFML / OS X developer

sb

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: [SOLVED] Using SMFL for drawing into a Qt Widget
« Reply #7 on: October 21, 2015, 08:16:45 pm »
Yes.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: [SOLVED] Using SMFL for drawing into a Qt Widget
« Reply #8 on: October 21, 2015, 08:18:20 pm »
Well, then I suppose you could send me a markdown file if you happen to write something -- I could post it for you. ;)
SFML / OS X developer

sb

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: [SOLVED] Using SMFL for drawing into a Qt Widget
« Reply #9 on: October 22, 2015, 12:34:29 pm »
I haven't used markdown before, so I hope this is okay. Feel free to change anything you want and thank you for posting. I know far too less about Qt and SFML to write such a tutorial from scratch.

Integrating SFML 2.3.2 to a Qt 5.5.1 interface
==============================================

How it worked in SFML 1.6
-------------------------

[A description of this.](http://www.sfml-dev.org/tutorials/1.6/graphics-qt.php)

Making it work in SFML 2.3.2
----------------------------

### Changed methods

The methods *Create* and *Display* were changed to lower-case in newer versions of SFML. Hence these changes must be applied to the code in the tutorial linked above. However, it seems like QWidget does also provide the method *create*, thus we have to be more precise and write *sf::create*. According to [this post](http://en.sfml-dev.org/forums/index.php?topic=13851.msg97124#msg97124), the argument in the *create*-statement should be cast to *sf::WindowHandle*, so the line with the *create*-statement ultimately becomes

*sf::RenderWindow::create((sf::WindowHandle) winId());* .

### Virtual methods
 
The derived class *QSFMLCanvas* inherits some virtual methods which have to be implemented. Adding

*QSFMLCanvas::~QSFMLCanvas() {}
void QSFMLCanvas::OnInit() {}
void QSFMLCanvas::OnUpdate() {}*

to the class definition should do it. (I think QSFMLCanvas is supposed to be virtual, so it might be better to declare those as virtual instead of dummy-implementing them.)

Everything should be working now.

### Resizing

When *QWidget::resize()* is called, the RenderWindow does not match the QWidget anymore. A solution to this (but maybe not the best one) is to call *sf::RenderWindow::create((sf::WindowHandle) winId());* once again subsequently.
« Last Edit: October 22, 2015, 12:37:50 pm by sb »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
SFML / OS X developer

sb

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: [SOLVED] Using SMFL for drawing into a Qt Widget
« Reply #11 on: October 22, 2015, 10:30:31 pm »
  /
\/