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

Author Topic: qt5 widgetHandle -> SFML2.0  (Read 3914 times)

0 Members and 2 Guests are viewing this topic.

uGhster

  • Newbie
  • *
  • Posts: 23
    • View Profile
qt5 widgetHandle -> SFML2.0
« on: September 26, 2016, 12:51:09 pm »
Hi I am trying to setup a QTSFMLCanvas as seen in eg: http://becomingindiedev.blogspot.se/2013/10/qt-5-and-sfml-20-integration.html

Qt5-widget has a winId() method that is supposed to return the native handler for the widget. On my platform (linux Arch 64bit) it is a long long unsigned int and RenderWindow seems to want a long unsigned int.

hence,
RenderWindow::create(reinterpret_cast<sf::WindowHandle>(winId()));

fails with: invalid cast from type 'WId {aka long long unsigned int}' to type 'sf::WindowHandle {aka long unsigned int}'

Is there a workaround or a way to convert the handle? I have been giving google hard time with this one and have found nothing.

static_cast just hangs the application.

Any ideas?


korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: qt5 widgetHandle -> SFML2.0
« Reply #1 on: September 26, 2016, 04:17:53 pm »
RenderWindow::create((sf::WindowHandle) winId());
In my case it worked fine. If you want to use Qt&SFML without implementing everything on your own you can use my library – QSFML. https://github.com/KoczurekK/QSFML

uGhster

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: qt5 widgetHandle -> SFML2.0
« Reply #2 on: September 26, 2016, 09:53:34 pm »
Belive me, I have tried this but there seems to be something changed. I have had Qt wrap up SFML nicely before.
Please try your lib, which seems to do a just that with Qt 5.7 and SFML 2.4 on a linux system and if that works then I'll be the first to confess that your lib has some vodoo-magic involved ;)
« Last Edit: September 26, 2016, 09:57:09 pm by uGhster »

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: qt5 widgetHandle -> SFML2.0
« Reply #3 on: September 26, 2016, 10:54:20 pm »
I've just recompiled library and it worked fine.  :o Do you have C++11 enabled? And what is your compiler version?

uGhster

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: qt5 widgetHandle -> SFML2.0
« Reply #4 on: September 27, 2016, 10:59:07 am »
There IS magic involved ;)
This is weird, I looked into SFML headers and this is how a WindowHandle is defined on my setup:

#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)

    // Window handle is Window (unsigned long) on Unix - X11
    typedef unsigned long WindowHandle;


and a WinId() returns a WId which is defined as a long long unsigned int.
static_cast fails aswell as reinterpret_cast.

I am running C++11 enabled on a gcc 6.2.1. on a 64bit system.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: qt5 widgetHandle -> SFML2.0
« Reply #5 on: September 27, 2016, 11:12:23 am »
long long unsigned int is implicitly convertible to long unsigned int (aka unsigned long), it may only show a warning due to potential type narrowing. So unless you want to remove the warning a cast is not needed and when you do use a cast, static_cast should be used.

This test code works fine on Ideone.
#include <iostream>

int main() {
        unsigned long ul = 10;
        long long unsigned int llui = 20;
       
        std::cout << ul << " " << llui << "\n";
       
        ul = llui;
        ul = static_cast<long unsigned int>(llui);
       
        std::cout << ul << " " << llui << "\n";
}

My guess is that because there was an issue ("hanging"?) when using an implicit cast or a static_cast, you assumed that this must be the origin of the issue, while it actually might be somewhere else entirely  (see also XY Problem). ;)
So what exactly is your problem with an implicit cast?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

uGhster

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: qt5 widgetHandle -> SFML2.0
« Reply #6 on: September 27, 2016, 11:55:50 am »
exactly, my guess is that WinId from QtWidget is not a handle but something else completely.
Seems that I am not the only one with this problem.
But what bothers me is that it works with some configurations.
« Last Edit: September 27, 2016, 12:03:35 pm by uGhster »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: qt5 widgetHandle -> SFML2.0
« Reply #7 on: September 27, 2016, 11:59:10 am »
Well don't just guess. Use your debugger or compile some test code and find out what is going on.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

uGhster

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: qt5 widgetHandle -> SFML2.0
« Reply #8 on: September 27, 2016, 12:24:20 pm »
Wow, that is why I asked the question here... to hopefully save the time and effort.
But you sir, seem to have time on your hand to go overboard to explain casting ;) \o/ yaay!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: qt5 widgetHandle -> SFML2.0
« Reply #9 on: September 27, 2016, 12:38:34 pm »
So instead of spending your own time on the problem you waste other people's time by not actually trying to figure out the problem and enjoy doing so. Thanks.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

uGhster

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: qt5 widgetHandle -> SFML2.0
« Reply #10 on: September 27, 2016, 12:41:46 pm »
Wasting your time?.. someone else might actually hold an answer to the problem instead of boosting their ego by posting how it in fact is possible to cast a long to a bool or whatnot. Well now your postcount went ++.