Prevent abnormal program termination
-
wrote on 27 Oct 2019, 19:29 last edited by aha_1980
Hi at all, I would like to know if exist in Qt a specific method to prevent abnormal program termination.
For example, if I've this code:QStringList lst = {"Bananas", "Apple", "Dog";} qDebug() << lst.at(0); qDebug() << lst.at(1); qDebug() << lst.at(2); qDebug() << lst.at(3);
The line qDebug() << lst.at(3); will cause an abnormal program termination because the index is out of range.
Have Qt a specific managment for these case to prevent the program crashes?
Thanks.Stefano
-
Hi,
There's nothing more in Qt than what is available in C++. Whether you do that with a Qt container or a STL, you will have the same result.
In any case, it's always better to check for your containers sizes when reaching for specific indexes like that. Otherwise you can use iterators for example.
-
wrote on 27 Oct 2019, 19:41 last edited by
Hi SGaist and many thanks for your answer :)
1/3