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
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
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:
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
Ah I think I understand what you are saying, Thanks once again : ]
Bookmarks