Results 1 to 2 of 2

Thread: pointers in c++

  1. #1
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default pointers in c++

    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

    Qt Code:
    1. pItem->bold = false;
    2.  
    3. if (pItem->m_pHL)
    4. {
    5.  
    6. // programe crashes here if (pItem->m_pHL->STestt()->IsTested())
    7. {
    8. pItem->bold = true;
    9. pItem->setOpen(true);
    10. }
    11.  
    12. QListViewItem *p = pItem->parent();
    13.  
    14. while(p)
    15. {
    16. ((CTestViewItem*)p)->bold = true;
    17. p = p->parent();
    18.  
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    and this the declaration of the pointer

    Qt Code:
    1. CHL m_pHL;
    To copy to clipboard, switch view to plain text mode 

    Can someone tell what i am doing wrong?
    Love::Peace

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: pointers in c++

    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.
    Last edited by Michiel; 4th June 2007 at 11:39. Reason: spelling error
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

Similar Threads

  1. Use/Misuse of Pointers
    By ct in forum General Programming
    Replies: 12
    Last Post: 9th May 2007, 00:43
  2. Pointer to a 2D array of pointers ??
    By aamer4yu in forum General Programming
    Replies: 2
    Last Post: 1st February 2007, 12:16
  3. another Q_OBJECT and pointers (?)
    By caminoix in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2006, 22:06
  4. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 16:48
  5. K&R's strcpy function - problem with pointers
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 8th January 2006, 16:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.