Nominate our 2022 Qt Champions!

Prevent abnormal program termination

  • 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() <<;
    qDebug() <<;
    qDebug() <<;
    qDebug() <<;

    The line qDebug() <<; 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?


  • Lifetime Qt Champion


    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.

  • Hi SGaist and many thanks for your answer :)

Log in to reply