• 13183阅读
  • 4回复

QApplication::sendEvent()发送事件 [复制链接]

上一主题 下一主题
离线feilong517
 

只看楼主 倒序阅读 楼主  发表于: 2010-03-26
在QT中,我自定义事件,然后用
QApplication::postEvent(obj, new QEvent(MyEvent));
发送事件。调试的时候,没问题。
但用QApplication::sendEvent(obj, new QEvent(MyEvent));
代替postEvent(),调试出错。
有高手知道问题出在哪里吗?
离线dbzhang800

只看该作者 1楼 发表于: 2010-03-26
引用楼主feilong517于2010-03-26 14:59发表的 QApplication::sendEvent()发送事件 :
在QT中,我自定义事件,然后用
QApplication::postEvent(obj, new QEvent(MyEvent));
发送事件。调试的时候,没问题。
但用QApplication::sendEvent(obj, new QEvent(MyEvent));
代替postEvent(),调试出错。
.......


bool QCoreApplication::sendEvent ( QObject * receiver, QEvent * event )   [static]
Sends event event directly to receiver receiver, using the notify() function. Returns the value that was returned from the event handler.

The event is not deleted when the event has been sent. The normal approach is to create the event on the stack, for example:
离线limeir
只看该作者 2楼 发表于: 2010-05-11
sendEvent()抛出事件后会马上处理,postEvent()后会把事件放入事件队列中,等待处理
Love is a butterfly!
离线nicker2010

只看该作者 3楼 发表于: 2010-05-13
void QCoreApplication::postEvent ( QObject * receiver, QEvent * event, int priority )
The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted. It is not safe to modify or delete the event after it has been posted.

The event is not deleted when the event has been sent. The normal approach is to create the event on the stack, for example:
QMouseEvent event(QEvent::MouseButtonPress, pos, 0, 0);
QApplication::sendEvent(mainWindow, &event);
离线nicker2010

只看该作者 4楼 发表于: 2010-05-13
void QCoreApplication::postEvent ( QObject * receiver, QEvent * event, int priority )
The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted. It is not safe to modify or delete the event after it has been posted.

bool QCoreApplication::sendEvent ( QObject * receiver, QEvent * event )   [static]
The event is not deleted when the event has been sent. The normal approach is to create the event on the stack, for example:
QMouseEvent event(QEvent::MouseButtonPress, pos, 0, 0);
QApplication::sendEvent(mainWindow, &event);
快速回复
限100 字节
 
上一个 下一个