Results 1 to 5 of 5

Thread: I press a button and receive 2 pressed() signals

  1. #1
    Join Date
    Aug 2010
    Posts
    20
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default I press a button and receive 2 pressed() signals

    Hi, I make a simple aplication with a button, and I connected to a slot.
    At first its looks easy, but then I realize that the pressed() signal arrives twice.

    I debug the code and find inside the qwidget.cpp code :

    Qt Code:
    1. switch (event->type()) {
    2. case QEvent::MouseMove:
    3. mouseMoveEvent((QMouseEvent*)event);
    4. break;
    5.  
    6. case QEvent::MouseButtonPress:
    7. // Don't reset input context here. Whether reset or not is
    8. // a responsibility of input method. reset() will be
    9. // called by mouseHandler() of input method if necessary
    10. // via mousePressEvent() of text widgets.
    11. #if 0
    12. resetInputContext();
    13. #endif
    14. mousePressEvent((QMouseEvent*)event);
    15. break;
    16.  
    17. case QEvent::MouseButtonRelease:
    18. mouseReleaseEvent((QMouseEvent*)event);
    To copy to clipboard, switch view to plain text mode 

    the first signal is emited after mousePressEvent event and the second after mouseMoveEvent
    Why MoveEvent throw a pressed() signal?

    I Add the call stack of the two cases

    Qt Code:
    1. Case 1: mousePressEvent
    2.  
    3. QtCored4.dll!QMetaObject::metacall(QObject* object = 0x01b054a0, QMetaObject::Call
    4. QtCored4.dll!QMetaObject::activate(QObject* sender = 0x01ae6cb0, QMetaObject* m =
    5. QtGuid4.dll!QAbstractButton::pressed(void) Line: 192, Byte Offsets: 0x2c C+
    6. QtGuid4.dll!QAbstractButtonPrivate::emitPressed(void) Line: 562, Byte Offsets: 0x4
    7. QtGuid4.dll!QAbstractButton::mousePressEvent(QMouseEvent* e = 0x1ba7d05c) Line: 10
    8. QtGuid4.dll!QWidget::event(QEvent* event = 0x1ba7d05c) Line: 8197, Byte Offsets: 0
    9. QtGuid4.dll!QAbstractButton::event(QEvent* e = 0x1ba7d05c) Line: 1080, Byte Offset
    10. QtGuid4.dll!QPushButton::event(QEvent* e = 0x1ba7d05c) Line: 683, Byte Offsets: 0x
    11. QtGuid4.dll!QApplicationPrivate::notify_helper(QObject* receiver = 0x01ae6cb0, QEv
    12. QtGuid4.dll!QApplication::notify(QObject* receiver = 0x01ae6cb0, QEvent* e = 0x1ba
    13.  
    14. Case 2: mouseMoveEvent
    15.  
    16. QtCored4.dll!QMetaObject::metacall(QObject* object = 0x01b054a0, QMetaObject::Call
    17. QtCored4.dll!QMetaObject::activate(QObject* sender = 0x01ae6cb0, QMetaObject* m =
    18. QtGuid4.dll!QAbstractButton::pressed(void) Line: 192, Byte Offsets: 0x2c C+
    19. QtGuid4.dll!QAbstractButtonPrivate::emitPressed(void) Line: 562, Byte Offsets: 0x4
    20. QtGuid4.dll!QAbstractButton::mouseMoveEvent(QMouseEvent* e = 0x1ba7d05c) Line: 114
    21. QtGuid4.dll!QWidget::event(QEvent* event = 0x1ba7d05c) Line: 8186, Byte Offsets: 0
    22. QtGuid4.dll!QAbstractButton::event(QEvent* e = 0x1ba7d05c) Line: 1080, Byte Offset
    23. QtGuid4.dll!QPushButton::event(QEvent* e = 0x1ba7d05c) Line: 683, Byte Offsets: 0x
    24. QtGuid4.dll!QApplicationPrivate::notify_helper(QObject* receiver = 0x01ae6cb0, QEv
    25. QtGuid4.dll!QApplication::notify(QObject* receiver = 0x01ae6cb0, QEvent* e = 0x1ba
    To copy to clipboard, switch view to plain text mode 

    ( Sorry I limitate the lines longitud to help to read it if same one need all the line don't hesitate to ask )

    Is it a Qt bug?

    Regards,

    Juan Manuel

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: I press a button and receive 2 pressed() signals

    Why are you showing Qt code not yours?
    Note that this is common use case so this kind of bug would be spotted immediately and fixed. This part of Qt code has couple years so I doubt this is Qt bug.
    Show us your code!
    Last edited by MarekR22; 20th November 2010 at 12:55. Reason: spelling corrections

  3. #3
    Join Date
    Aug 2010
    Posts
    20
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: I press a button and receive 2 pressed() signals

    Hi I found that this bug was reported in 2006 and was assinged to study severals times, the last one was in may 2010, and is reported in linux embbeded, so I also add info to the apen issue with extra info and platform (Windows Mobile).

    And Yes, is a large and prone issue.

    Thanks to all

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: I press a button and receive 2 pressed() signals

    Just a note that if this is Qt4 behavior, it will not be fixed in Qt4 because it will break compatibility with previous versions. The earliest this behavior can change is Qt5.
    Don't get your hopes up that if you file a bug report that it will get magically fixed in the next minor release.

    And I can't imagine that the mouse pressed signal while moving is a huge problem. In fact, in some cases it is even wanted! You can move the button without pressing any button too.

  5. #5
    Join Date
    Aug 2010
    Posts
    20
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: I press a button and receive 2 pressed() signals

    Yes you are rigth, perhaps I should use click signal instead of pressed.

Similar Threads

  1. Replies: 6
    Last Post: 4th October 2010, 03:19
  2. Replies: 6
    Last Post: 21st August 2010, 21:09
  3. Replies: 1
    Last Post: 17th May 2010, 16:15
  4. Replies: 3
    Last Post: 17th November 2009, 21:10
  5. Getting the row for button pressed
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2007, 15:45

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
  •  
Qt is a trademark of The Qt Company.