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);