I'm experiencing a strange phenomenon: it seems that on some occasions, the wrong virtual function is called at certain events on MacOS X, while all works fine on Linux and Windows.

consider the following:

Qt Code:
  1. class A : public QGLWidget {
  2. protected:
  3. virtual void foo() {}
  4. private:
  5. virtual void paintEvent(QPaintEvent *event);
  6. };
  7.  
  8. void A::paintEvent(QPaintEvent *event) {
  9. foo();
  10. }
  11.  
  12. class B : public A {
  13. protected:
  14. virtual void foo();
  15. };
  16.  
  17. void B::foo() {
  18. std::cout << "hello from B::foo!" << std::endl;
  19. }
To copy to clipboard, switch view to plain text mode 

when I use the above in the following manner:

Qt Code:
  1. B b;
  2. b.show()
To copy to clipboard, switch view to plain text mode 

then, it seems that on the first occasion the paintEvent() is called on b, it is in fact an object of class A, and thus A::foo() is called from paintEvent(). interestingly , on the second or so occasion onwards, the object will act as being of class B, and thus B::foo() will be called. on both occasions, the value of the this pointer is the same.

the expectation would be that in all occasions B::foo() is called.

the above works fine on Linux and Windows, but works in the strange way as explained above on MacOS X.

This is with Qt 4.5 (2009.03) and the latest XCode.

I wonder if anyone has experienced this issue...