Results 1 to 3 of 3

Thread: how to check for NULL reference?

  1. #1
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    1

    Default how to check for NULL reference?

    In my project I'm having a hash member of :

    Qt Code:
    1. QHash<int,graphDialog *> dialogs;
    To copy to clipboard, switch view to plain text mode 

    where graphDialog class is a member of QDialog.

    while I'm iterating through this hash, I want to make sure that the QDialog member I'm iterating is not null ( not destroyed ).
    How do I do that?
    I tried the following :

    Qt Code:
    1. QHashIterator<int, graphDialog *> i(dialogs);
    2. while (i.hasNext()) {
    3. i.next();
    4. if(i.value() != NULL ){ ... }
    5. }
    To copy to clipboard, switch view to plain text mode 
    although when the dialog is destroyed it is not equal to NULL and passes through if :/

    then I used the so-called guarded pointer class QPointer and did the following:

    Qt Code:
    1. QHashIterator<int, graphDialog *> i(dialogs);
    2. while (i.hasNext()) {
    3. i.next();
    4. QPointer<graphDialog> test = i.value();
    5. if(!test){ .... }
    6. }
    To copy to clipboard, switch view to plain text mode 
    however this time I get a segmentation error while the QPointer is being created.
    I thought this class was meant to build for this mission, but it seems to suffer from the same issue (null reference).

    also there is nothing like isClosed,isDestroyed,isNull for QDialog if I'm not mistaken ...
    So how do I check for it , please help

  2. #2
    Join Date
    Nov 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to check for NULL reference?

    Gaurd Pointer provides an API QPointer::isNull() for NULL check. Try using this API.
    I hope it works.


    Cheers
    Gopikrishna

  3. #3
    Join Date
    Jan 2006
    Location
    Shanghai, China
    Posts
    52
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to check for NULL reference?

    You should use
    Qt Code:
    1. QHash<int, QPointer<graphDialog> > dialogs;
    To copy to clipboard, switch view to plain text mode 
    instead.
    1. Users don't have the manual, and if they did, they wouldn't read it.
    2. In fact, users can't read anything, and if they could, they wouldn't want to.

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Undefined reference to crt
    By derektaprell in forum Installation and Deployment
    Replies: 0
    Last Post: 20th October 2009, 08:34
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  4. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  5. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15

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.