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. Index out of range error
Forum Updated to NodeBB v4.3 + New Features

Index out of range error

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstringlistqstringconcatanationruntimeerror
5 Posts 3 Posters 1.8k 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.
  • L Offline
    L Offline
    Lasith
    wrote on last edited by
    #1

    In my qt c++ application when I insert a text value concatenated with a comma opeartor I get a runtime error stating "Index out of range"! But with out comma if I only insert the line edit value to the QStringList there is no runtime error!

    Following code works

    QStringList myList;
    myList<<ui->lineedit1->text();

    but following gives a runtime error!

    QStringList myList;
    myList<<ui->lineedit1->text()+",";

    How can I correct this issue?

    J.HilkJ 1 Reply Last reply
    0
    • L Lasith

      In my qt c++ application when I insert a text value concatenated with a comma opeartor I get a runtime error stating "Index out of range"! But with out comma if I only insert the line edit value to the QStringList there is no runtime error!

      Following code works

      QStringList myList;
      myList<<ui->lineedit1->text();

      but following gives a runtime error!

      QStringList myList;
      myList<<ui->lineedit1->text()+",";

      How can I correct this issue?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Lasith by using the intended QStringList functions instead if an abstract and overloaded operator

      QStringList myList;
      myList.append(ui->lineedit1->text()+",");


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      L 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @Lasith by using the intended QStringList functions instead if an abstract and overloaded operator

        QStringList myList;
        myList.append(ui->lineedit1->text()+",");

        L Offline
        L Offline
        Lasith
        wrote on last edited by
        #3

        @J.Hilk Thanx but I still get the run time error :(

        J.HilkJ 1 Reply Last reply
        0
        • L Lasith

          @J.Hilk Thanx but I still get the run time error :(

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Lasith are you sure it actually crashes at that line?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            Normally its the

            that can give "index out of range error"

            not when inserting ?

            1 Reply Last reply
            0

            • Login

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