Results 1 to 7 of 7

Thread: checking for null

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 127 Times in 121 Posts

    Default Re: checking for null

    Quote Originally Posted by drkbkr
    This may be a ridiculous question. And it may be just a C++ question. But I am totally lost here.

    I would think that if I have declared an object, say a QListView, in a header file, but have not yet initialized that object, I could test for that declared but not initialized state with

    Qt Code:
    1. if(sequenceList == NULL)
    To copy to clipboard, switch view to plain text mode 

    where sequenceList is the name of my QListView. But it is always returning false, whether initialized or not. I've also tried:

    Qt Code:
    1. if(sequenceList == null)
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. if(sequenceList == 0)
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong here? Any help would be greatly appreciated.

    Thanks,
    Derek
    Depends on your compiler but pointers are rarely set to 0. You've got to do it in the constructor:

    Qt Code:
    1. SomeClass::SomeClass(...)
    2. : sequenceList(0)
    3. {
    4. //other stuff
    5. }
    To copy to clipboard, switch view to plain text mode 

    which is the same as :

    Qt Code:
    1. SomeClass::SomeClass(...)
    2. {
    3. sequenceList = 0;
    4. //other stuff
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by fullmetalcoder; 10th March 2006 at 21:16.
    Current Qt projects : QCodeEdit, RotiDeCode

  2. The following user says thank you to fullmetalcoder for this useful post:

    drkbkr (10th March 2006)

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Adding spell checking to lineedits, textedits, ...
    By jiveaxe in forum Qt Programming
    Replies: 12
    Last Post: 7th October 2009, 09:04
  3. Crash while checking the index is of particular level of a tree
    By kapil sharma in forum Qt Programming
    Replies: 1
    Last Post: 27th November 2008, 07:21
  4. StyleSheet syntax checking
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2008, 10:09
  5. Checking if bad pointer?
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2007, 09:06

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
  •  
Qt is a trademark of The Qt Company.