akos.maroy
3rd July 2009, 11:06
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:
class A : public QGLWidget {
protected:
virtual void foo() {}
private:
virtual void paintEvent(QPaintEvent *event);
};
void A::paintEvent(QPaintEvent *event) {
foo();
}
class B : public A {
protected:
virtual void foo();
};
void B::foo() {
std::cout << "hello from B::foo!" << std::endl;
}
when I use the above in the following manner:
B b;
b.show()
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...
consider the following:
class A : public QGLWidget {
protected:
virtual void foo() {}
private:
virtual void paintEvent(QPaintEvent *event);
};
void A::paintEvent(QPaintEvent *event) {
foo();
}
class B : public A {
protected:
virtual void foo();
};
void B::foo() {
std::cout << "hello from B::foo!" << std::endl;
}
when I use the above in the following manner:
B b;
b.show()
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...