A pointer member variable having different values
        Posted  
        
            by 
                Rohan Prabhu
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Rohan Prabhu
        
        
        
        Published on 2011-01-02T14:54:29Z
        Indexed on 
            2011/01/02
            18:53 UTC
        
        
        Read the original article
        Hit count: 194
        
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?
© Stack Overflow or respective owner