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. ASSERT occurs on a.at(5).isNull()

ASSERT occurs on a.at(5).isNull()

Scheduled Pinned Locked Moved Solved General and Desktop
qstring
2 Posts 2 Posters 1.1k Views 1 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.
  • R Offline
    R Offline
    rbmisc
    wrote on last edited by
    #1

    Here is the code I'm trying:
    #include <QTextStream>

    int main(void)
    {

    QTextStream out(stdout);
    
    QString a = "Eagle";
    
    out << a[0] << endl;
    out << a[4] << endl;
    
    out << a.at(0) << endl;
    
    if (a.at(5).isNull())
    {
        out << "Outside the range of the string" << endl;
    }
    
    return 0;
    

    }
    Here is the output:
    E
    e
    E
    ASSERT: "uint(i) < uint(size())" in file ../../Qt/5.6/clang_64/lib/QtCore.framework/Headers/qstring.h, line 868

    Isn't a.at(5).isNull() the correct coding?

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #2

      The assertion is expected behaviour for QString::at

      The position must be a valid index position in the string (i.e., 0 <= position < size()).

      Instead, you should do something like:

      if (5 >= a.size())
      {
          out << "Outside the range of the string" << endl;
      }
      

      Cheers.

      1 Reply Last reply
      2

      • Login

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