Is it not possible to post custom events (across thread) to a QThread descendant? Or am I doing something wrong? Should I create a child for the thread and post events to the child object to get events delivered to the correct thread?

The code below illustrates the problem:
Qt Code:
  1. #include <QtGui>
  2. #include <QtDebug>
  3.  
  4. class MyThread : public QThread
  5. {
  6. public:
  7. MyThread(QObject* parent = 0) : QThread(parent)
  8. {
  9. }
  10.  
  11. protected:
  12. void run()
  13. {
  14. qDebug() << "MyThread::run()" << QThread::currentThread() << this->thread();
  15. exec();
  16. }
  17.  
  18. void customEvent(QEvent* event)
  19. {
  20. qDebug() << "MyThread::customEvent()" << QThread::currentThread() << this->thread();
  21. // a long loop here will naturally block GUI
  22. qDebug() << "LOOP BEGIN";
  23. for (uint i = 0; i < -1; ++i);
  24. qDebug() << "LOOP END";
  25. }
  26. };
  27.  
  28. class EventButton : public QPushButton
  29. {
  30. Q_OBJECT
  31.  
  32. public:
  33. EventButton() : QPushButton("Post an event")
  34. {
  35. mythread = new MyThread(this); // creating without parent has no effect
  36. mythread->start();
  37. connect(this, SIGNAL(clicked()), this, SLOT(postEvent()));
  38. }
  39.  
  40. private slots:
  41. void postEvent()
  42. {
  43. qDebug() << "EventButton::postEvent()" << QThread::currentThread() << this->thread();
  44. QApplication::postEvent(mythread, new QEvent(QEvent::User));
  45. }
  46.  
  47. private:
  48. MyThread* mythread;
  49. };
  50.  
  51. int main(int argc, char *argv[])
  52. {
  53. QApplication a(argc, argv);
  54. qDebug() << "main()" << QThread::currentThread();
  55. EventButton b;
  56. b.show();
  57. a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
  58. return a.exec();
  59. }
  60.  
  61. #include "main.moc"
To copy to clipboard, switch view to plain text mode 

Please, spot a mistake there..