Results 1 to 8 of 8

Thread: Qt5 native messages not propogated?

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt5 native messages not propogated?

    I use Qt 4.8 with SFML 2.0, but I just migrated to Qt 5.0. I'm programming on Windows 7, 32 bit, and I use MinGW (4.7.2) as my compiler.

    The basic layout of my application is a QWidget as the "main window", with several QWidget side panels, and in the center, a QWidget mixed with SFML ("sfml window"), that SFML draws and handles events for.

    In Qt 4.8, SFML keyboard events for that central SFML window worked just fine, but in Qt 5.0, the keyboard events aren't reaching SFML. The keyboard events are reaching the QWidget that SFML is attached to (I breakpointed on keyPressEvent() to test), but SFML's keyboard events stopped working in Qt 5. Not all events, mouse events work fine, but the keyboard events don't get forwarded to SFML by Qt.

    I even tried to grabKeyboard() on the QWidget/SFML window to check. Didn't help.
    Qt Code:
    1. class AreaWindow : public QWidget, public sf::RenderWindow
    2. {
    3. Q_OBJECT
    4. public:
    5. AreaWindow();
    6. ~AreaWindow();
    7.  
    8. //...other functions...
    9. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. AreaWindow::AreaWindow()
    2. : QWidget(nullptr), isInitialized(false)
    3. {
    4. //Setup some states to allow direct rendering into the widget
    5. QWidget::setAttribute(Qt::WA_PaintOnScreen);
    6. QWidget::setAttribute(Qt::WA_OpaquePaintEvent);
    7. QWidget::setAttribute(Qt::WA_NoSystemBackground);
    8. QWidget::setAttribute(Qt::WA_PaintUnclipped);
    9.  
    10. //Set strong focus to enable keyboard events to be received
    11. QWidget::setFocusPolicy(Qt::StrongFocus);
    12. }
    13.  
    14. void AreaWindow::showEvent(QShowEvent*)
    15. {
    16. if(!this->isInitialized)
    17. {
    18. //Under X11, we need to flush the commands sent to the server to ensure that
    19. //SFML will get an updated view of the windows
    20. #ifdef Q_WS_X11
    21. XFlush(QX11Info::display());
    22. #endif
    23.  
    24. //Create the SFML window with the widget handle
    25. sf::RenderWindow::create((HWND)this->winId());
    26.  
    27. this->isInitialized = true;
    28. }
    29. }
    30.  
    31. QPaintEngine *AreaWindow::paintEngine() const
    32. {
    33. //We make the paintEvent function return a null paint engine. This functions works together with
    34. //the WA_PaintOnScreen flag to tell Qt that we're not using any of its built-in paint engines.
    35. return nullptr;
    36. }
    37.  
    38. void AreaWindow::paintEvent(QPaintEvent *event)
    39. {
    40. //Clear the window (using SFML).
    41. sf::RenderWindow::clear(Global::Window::ClearColor.ToSfmlColor());
    42.  
    43. //Start the camera off on World mode.
    44. this->SetCameraMode(CameraMode::World);
    45.  
    46. //...draw code goes here...
    47.  
    48. //Display on screen (using SFML).
    49. sf::RenderWindow::display();
    50. }
    To copy to clipboard, switch view to plain text mode 

    To be clear, this worked in Qt 4.8 - some change between Qt 4.8 and Qt 5.0 stopped native Win32 keyboard events from being forwarded to SFML. Any ideas?

    [Edit:] SFML also isn't receiving the focus/unfocus events (sf::Event::GainedFocus and sf::Event::LostFocus), even though the QWidget is (QWidget::focusInEvent(), QWidget::focusOutEvent()).
    This is not an SFML-related problem, the QWidget is stopping the Win32 events (it seems to me).
    Last edited by ComServant; 27th December 2012 at 17:13. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt5 native messages not propogated?

    Qt doesn't "forward" any events to third party libraries. If you want that, you have to explicitly do it by overriding proper event handlers or installing event filters and doing whatever needs to be done for the events to reach wanted destination.

    If you don't override a specific event handler, that event gets ignored and propagates (in case of input events) to the parent. That's the default event handling in Qt both in Qt4 and Qt5.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt5 native messages not propogated?

    I'm not suggesting Qt intentionally interacts with third party APIs. All I'm saying is that Win32 messages that previously reached a third party library in Qt 4.8 (and in Qt 4.7, and I think 4.6 also), now are not reaching it in Qt 5, even though it's still reaching the QWidget. I'm not asking for Qt to forward anything. I'm asking why it's blocking what it previously wasn't.

    I don't understand how the QWidgets are implemented in Win32, but I'm wondering if a perhaps in the promotion of QWidgets to their own module, as well as any possible QPA code changes, Qt 5 might be accidentally blocking certain Win32 messages. Again, not knowing how it works under the hood, I wonder if perhaps it's failing to call DefWndProc() on a few messages that used to call it on. If so, why the change? If the change is accidental, what other side-effects might this cause in compatibility?

    Why does it forward some Win32 messages but not others? Why not forward them all? Why not block them all? A change was made that affects the Win32 events that reach the window. The question is, why? What purpose does it serve, and was it accidental?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt5 native messages not propogated?

    Quote Originally Posted by ComServant View Post
    I'm not suggesting Qt intentionally interacts with third party APIs. All I'm saying is that Win32 messages that previously reached a third party library in Qt 4.8 (and in Qt 4.7, and I think 4.6 also), now are not reaching it in Qt 5, even though it's still reaching the QWidget. I'm not asking for Qt to forward anything. I'm asking why it's blocking what it previously wasn't.
    How were they "reaching" the library?

    Why does it forward some Win32 messages but not others? Why not forward them all? Why not block them all? A change was made that affects the Win32 events that reach the window. The question is, why? What purpose does it serve, and was it accidental?
    If you want to handle windows events then install a native event filter on the application object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt5 native messages not propogated?

    I'm not sure. I'll just looked at the source of SFML, and this is what it looks like:
    1. Qt creates the window
    2. Qt gives me the HWND
    3. I give SFML the HWND
    4. SFML attaches it's own WndProc callback function to it, but saves the previous (Qt's) WndProc.
    5. SFML receives the messages, processes them, then forwards them to the previous (Qt's) WndProc.


    So it looks like SFML gets to process the Win32 events before Qt. I don't know why SFML is not processing the key presses (but is receiving mouse messages) then, but why it was previously with Qt 4.8.

    It looks like I was investigating the wrong API - thanks for the help.

  6. #6
    Join Date
    Feb 2014
    Posts
    24
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Qt5 native messages not propogated?

    Greetings,

    I've been on this case for awhile now and I still couldn't figure why SFML does not process mouse wheel and keyboard inputs anymore.

    Could you tell us how you fixed it?

    Note: It is clearly a QT modification from 4.8 to 5.x that brought this issue.

    Thank you!

  7. #7
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt5 native messages not propogated?

    It's definitely a Qt issue, and I haven't gotten it working. I'm using Qt 5.0.1 - maybe someone has fixed it in a more recent update, but I can't check anytime soon.

    I receive events for: Mouse movement and mouse button presses (include the middle button, which is the scroll wheel), but I don't receive events for mouse wheel movement or keypresses, even though the QWidget is clearly getting them.

    I wonder if Qt treats mouse wheel in the same way as keypresses, and whether it is failing to call the Win32 DefWindowProc on them, or something.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt5 native messages not propogated?

    Please provide a minimal compilable example demonstrating the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Get Windows Messages
    By METEOR7 in forum Qt Programming
    Replies: 7
    Last Post: 2nd January 2012, 17:27
  2. Printing Messages Only once
    By purplecoast in forum Qt Programming
    Replies: 0
    Last Post: 3rd October 2010, 21:15
  3. Getting messages sent by PostMessage
    By Luc4 in forum Qt Programming
    Replies: 5
    Last Post: 19th May 2010, 16:13
  4. Qt4 no debug messages
    By TheKedge in forum Newbie
    Replies: 3
    Last Post: 23rd January 2006, 17:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.