PDA

View Full Version : I press a button and receive 2 pressed() signals



JuanMO
19th November 2010, 18:52
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 :



switch (event->type()) {
case QEvent::MouseMove:
mouseMoveEvent((QMouseEvent*)event);
break;

case QEvent::MouseButtonPress:
// Don't reset input context here. Whether reset or not is
// a responsibility of input method. reset() will be
// called by mouseHandler() of input method if necessary
// via mousePressEvent() of text widgets.
#if 0
resetInputContext();
#endif
mousePressEvent((QMouseEvent*)event);
break;

case QEvent::MouseButtonRelease:
mouseReleaseEvent((QMouseEvent*)event);


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



Case 1: mousePressEvent

QtCored4.dll!QMetaObject::metacall(QObject* object = 0x01b054a0, QMetaObject::Call
QtCored4.dll!QMetaObject::activate(QObject* sender = 0x01ae6cb0, QMetaObject* m =
QtGuid4.dll!QAbstractButton::pressed(void) Line: 192, Byte Offsets: 0x2c C+
QtGuid4.dll!QAbstractButtonPrivate::emitPressed(vo id) Line: 562, Byte Offsets: 0x4
QtGuid4.dll!QAbstractButton::mousePressEvent(QMous eEvent* e = 0x1ba7d05c) Line: 10
QtGuid4.dll!QWidget::event(QEvent* event = 0x1ba7d05c) Line: 8197, Byte Offsets: 0
QtGuid4.dll!QAbstractButton::event(QEvent* e = 0x1ba7d05c) Line: 1080, Byte Offset
QtGuid4.dll!QPushButton::event(QEvent* e = 0x1ba7d05c) Line: 683, Byte Offsets: 0x
QtGuid4.dll!QApplicationPrivate::notify_helper(QOb ject* receiver = 0x01ae6cb0, QEv
QtGuid4.dll!QApplication::notify(QObject* receiver = 0x01ae6cb0, QEvent* e = 0x1ba

Case 2: mouseMoveEvent

QtCored4.dll!QMetaObject::metacall(QObject* object = 0x01b054a0, QMetaObject::Call
QtCored4.dll!QMetaObject::activate(QObject* sender = 0x01ae6cb0, QMetaObject* m =
QtGuid4.dll!QAbstractButton::pressed(void) Line: 192, Byte Offsets: 0x2c C+
QtGuid4.dll!QAbstractButtonPrivate::emitPressed(vo id) Line: 562, Byte Offsets: 0x4
QtGuid4.dll!QAbstractButton::mouseMoveEvent(QMouse Event* e = 0x1ba7d05c) Line: 114
QtGuid4.dll!QWidget::event(QEvent* event = 0x1ba7d05c) Line: 8186, Byte Offsets: 0
QtGuid4.dll!QAbstractButton::event(QEvent* e = 0x1ba7d05c) Line: 1080, Byte Offset
QtGuid4.dll!QPushButton::event(QEvent* e = 0x1ba7d05c) Line: 683, Byte Offsets: 0x
QtGuid4.dll!QApplicationPrivate::notify_helper(QOb ject* receiver = 0x01ae6cb0, QEv
QtGuid4.dll!QApplication::notify(QObject* receiver = 0x01ae6cb0, QEvent* e = 0x1ba


( 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

MarekR22
20th November 2010, 12:54
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!

JuanMO
20th November 2010, 20:18
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

tbscope
21st November 2010, 06:08
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.

JuanMO
21st November 2010, 06:58
Yes you are rigth, perhaps I should use click signal instead of pressed.