PDA

View Full Version : How to Handle new Qt?



ashukla
3rd March 2008, 05:14
Dear Qtians!
I have one question about new.

//UI_DLGTEXTSCROLLER_H
QPushButton *pbOk;
void setupUi(QDialog *dlgTextScroller)
{
.....
....
pbOk = new QPushButton(dlgTextScroller);
pbOk->setObjectName(QString::fromUtf8("pbOk"));
pbOk->setGeometry(QRect(293, 197, 154, 27));
..........
.........
}
How a way pbOk handle error when bad allocation exists due to some reason.
I am not seeing any try{ }catch{ } block for that.

wysota
3rd March 2008, 07:12
How a way pbOk handle error when bad allocation exists due to some reason.

Very simple - it doesn't. In most cases it would be a fatal error anyway...

ashukla
3rd March 2008, 11:08
Very simple - it doesn't. In most cases it would be a fatal error anyway...
Then, I should use try{} and catch{} block for new or not in my classes.
In some cases, if I does not use try{} catch{} for new and due to some reason object does not allocated and when I destroy object it gives segmentation fault.

wysota
3rd March 2008, 11:50
Then, I should use try{} and catch{} block for new or not in my classes.
It depends on you. If you can recover from a lack of memory and you are worried they might happen, feel free to do it.


In some cases, if I does not use try{} catch{} for new and due to some reason object does not allocated and when I destroy object it gives segmentation fault.
Most probably you have an error in your code (a dangling pointer perhaps) that is completely unrelated to exceptions thrown by operator new or lack of memory.