I have this code:

Qt Code:
  1. #include <QtCore/QCoreApplication>
  2. #include <QtCore/QtGlobal>
  3. #include <QtCore/QtDebug>
  4. #include <QtCore/QEventLoop>
  5. #include <QtCore/QTimer>
  6.  
  7. #define USE_LOOP2 0
  8.  
  9. #if USE_LOOP2 == 1
  10. static QEventLoop *loop2=0;
  11. #endif
  12.  
  13. class Base
  14. {
  15. public:
  16. Base()
  17. {
  18. #if USE_LOOP2 == 1
  19. loop2 = new QEventLoop;
  20. #endif
  21. };
  22. virtual void foo() = 0;
  23. static QEventLoop * eventLoop()
  24. {
  25. #if USE_LOOP2 == 1
  26. return loop2;
  27. #else
  28. if (loop) {
  29. return loop;
  30. } else {
  31. return new QEventLoop(qApp);
  32. }
  33. #endif
  34. }
  35. virtual ~Base(){};
  36. private:
  37. #if USE_LOOP2 != 1
  38. static QEventLoop *loop;
  39. #endif
  40. };
  41.  
  42. #if USE_LOOP2 != 1
  43. QEventLoop *Base::loop=0;
  44. #endif
  45.  
  46. class A : public Base
  47. {
  48. public:
  49. A(){}
  50. virtual ~A(){}
  51. void foo()
  52. {
  53. qDebug() << "Run exec...";
  54. qDebug() << eventLoop()->exec();
  55. qDebug() << "Exit exec...";
  56. }
  57. };
  58.  
  59. int main(int argc, char *argv[])
  60. {
  61. QCoreApplication app(argc, argv);
  62. A a;
  63. QTimer::singleShot(6000, a.eventLoop(), SLOT(quit()));
  64. a.foo();
  65. QTimer::singleShot(6000, &app, SLOT(quit()));
  66. return app.exec();
  67. }
To copy to clipboard, switch view to plain text mode 

If i use global static pointer loop2 - all work. If i use static loop pointer as member for class Base - event never exit (in my other program exec() just return -1 value). For test you can change USE_LOOP2 to 0 or 1 and try yourself.