Results 1 to 7 of 7

Thread: Error when trying to update TableView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Location
    New Zealand
    Posts
    54
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    23

    Default Re: Error when trying to update TableView

    Thanks a lot, it works now, if you have time could you please tell me the reasoning behind the following lines of code:

    [code]
    if (!channelsView || !model) { // check whether pointers are not 0.
    return;
    }

    Thanks

  2. #2
    Join Date
    Nov 2007
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default Re: Error when trying to update TableView

    Quote Originally Posted by Ferric View Post
    Thanks a lot, it works now, if you have time could you please tell me the reasoning behind the following lines of code:

    [code]
    if (!channelsView || !model) { // check whether pointers are not 0.
    return;
    }

    I apologize you annoying.
    In this case, the code is not necessary.

    This check is necessary, in the following case.
    • Always initialize the pointer with 0, before using the pointer.
    • Always assign 0 to the pointer which is referring to nothing.
    • Make the pointer refer to object with "new", when it becomes necessary.
    • Delete the pointer to object, when it becomes unnecessary, and assign 0 to the pointer.
    • "new" may throw std::bad_alloc when the memory becomes insufficient. so always use "try" keyword, and "catch" the exception. In particular, never throw any exceptions out of constractor.
    • Always check the pointer whether it is not 0, before which is used.


    If you don't need std::bad_exception, you can write the following code.

    Qt Code:
    1. QTableView *channelsView = new(nothrow) QTableView();
    To copy to clipboard, switch view to plain text mode 

    "new(nothrow)" does not throw std::bad_exec, and if there is not enough memory, it returns 0.
    but I have rarely seen this using up to now, on the Web.

    I'm sorry in poor English.
    kichi

  3. #3
    Join Date
    Dec 2009
    Location
    New Zealand
    Posts
    54
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    23

    Default Re: Error when trying to update TableView

    Ah I think I understand what you are saying, Thanks once again : ]

Similar Threads

  1. tableview
    By GuL in forum Newbie
    Replies: 1
    Last Post: 26th August 2008, 17:18
  2. TableView and QDataWidgetMapper
    By kramed in forum Qt Programming
    Replies: 1
    Last Post: 17th June 2008, 04:41
  3. tableView Problem
    By hrcariaga in forum Newbie
    Replies: 5
    Last Post: 7th February 2008, 08:29
  4. help in tableview
    By bala in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 15:46
  5. tableview and layouts
    By zorro68 in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2007, 17:21

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.