[Qt-interest] A pointer member variable having different values

Rohan Prabhu rohan at rohanprabhu.com
Sun Jan 2 15:55:30 CET 2011


Ok, to begin with, this is my code:

    HyperSprite::HyperSprite()
    {
        _view = 0;
    }

    void HyperSprite::publish(QGraphicsView* view) {
        _view = view;
    }

    void HyperSprite::getKFrame() {
        if(_view != 0) {
            qDebug()<<(void*)_view;
        }
    }

Now, if I call `HyperSprite::getKFrame()` from within `main()`, I get
the output:

    0xbf8ffb84

I have a TCP server, which requires this `QGraphicsView*` variable. So
whenever a new connection is made, `HyperSprite::getKFrame()` is
called. However, whenever I make a connection to my server, this is
the output:

    0x1e425ff

I honestly don't understand this. Shouldn't the value of a member
remain same throughout? Why is the pointer value changing? As is
obvious, whenever I try to use the _view pointer to access any of its
members, a Segmentation Fault occurs. I tried using QSharedPointer,
but it also results in the same problem. The data of the
QSharedPointer automatically changes. Why is this happening?



More information about the Qt-interest-old mailing list