Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Prevent abnormal program termination
Forum Update on Tuesday, May 27th 2025

Prevent abnormal program termination

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 319 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stefanoxjx
    wrote on 27 Oct 2019, 19:29 last edited by aha_1980
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 27 Oct 2019, 19:33 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • S Offline
        S Offline
        Stefanoxjx
        wrote on 27 Oct 2019, 19:41 last edited by
        #3

        Hi SGaist and many thanks for your answer :)

        1 Reply Last reply
        0

        1/3

        27 Oct 2019, 19:29

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved