PDA

View Full Version : pointers in c++



:db:sStrong
4th June 2007, 09:06
Hello folks

I have a simple question regarding pointers. I have a programe which should make some of the items of a qlistview bold. I have declared a pointer to the class where i have functions who can distinguish which items should be bold. But the crashes on that pointer.

Here is my code




pItem->bold = false;

if (pItem->m_pHL)
{

// programe crashes here if (pItem->m_pHL->STestt()->IsTested())
{
pItem->bold = true;
pItem->setOpen(true);
}

QListViewItem *p = pItem->parent();

while(p)
{
((CTestViewItem*)p)->bold = true;
p = p->parent();

}
}


and this the declaration of the pointer




CHL m_pHL;


Can someone tell what i am doing wrong?

Michiel
4th June 2007, 09:56
There are several possibilities.

* pItem->m_pHL is a dangling pointer. This means it once pointed to something which is deleted by this point. When you dereference (->) it, the program crashes.

* pItem->m_pHL->STestt() is a dangling pointer.

* pItem->m_pHL->STestt() is NULL.