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. QStringList bug - sensitive to content

QStringList bug - sensitive to content

Scheduled Pinned Locked Moved General and Desktop
14 Posts 3 Posters 6.0k 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.
  • S Offline
    S Offline
    steveheflin
    wrote on last edited by
    #1

    If an attempt is made to add QString("DISPLAY_WAVEFORM") to a QStringList, all members of the list vanish.
    QString s1, s2, s3, s4, sAll;
    s1 = QString("ECG I");
    s2 = QString("ECG");
    s3 = QString("DISPLAY_WAVEFORM");
    s4 = QString("0");
    QStringList inList;
    inList << s1 << s2 << s3 << s4;
    sAll = QString("%1 %2 %3 %4").arg(inList[0]).arg(inList[1]).arg(inList[2]).arg(inList[3]);
    SEGMENTATION FAULT - index out of range

    Simply change the string DISPLAY_WAVEFORM to something like "word" and the problem goes away

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stereomatching
      wrote on last edited by
      #2

      QStringList start from index 0, end by index 3 if you only append 4 QString into it
      0, 1, 2, 3

      1 Reply Last reply
      0
      • S Offline
        S Offline
        steveheflin
        wrote on last edited by
        #3

        This was my first post and I didn't realize the code would be reformatted. Also, the inList[4] was a typo, Finally, here's what I meant to post:
        @ QString s1, s2, s3, s4, sAll;
        s1 = QString(“ECG I”);
        s2 = QString(“ECG”);
        s3 = QString(“DISPLAY_WAVEFORM”);
        s4 = QString(“0”);
        QStringList inList;
        inList << s1 << s2 << s3 << s4;
        sAll = QString(”%1 %2 %3 %4”)
        .arg(inList[0]).arg(inList[1]).arg(inList[2]).arg(inList[3]);

        SEGMENTATION FAULT – index out of range
        @
        Simply change the string DISPLAY_WAVEFORM to something like “word” and the problem goes away
        I have a little project all tarballed and ready to emal if anybody wants it

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          welcome to devnet

          You may be right that there is a bug. However, one cannot judge from the snippet you are posting. What are the values of inList0, ... , inList3?

          If you like to combine strings from a QStringList into one QString you can use also method "join":http://qt-project.org/doc/qt-4.8/qstringlist.html#join

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            steveheflin
            wrote on last edited by
            #5

            The values I showed are the actual ones I'm using. The goal is not to combine the strings, I need all the strings in a list so I can enter them into columns in a database. The snippet I posted is only to demonstrate the bug, not to show a stupid way to combine strings.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              [quote author="steveheflin" date="1345377423"]This was my first post and I didn't realize the code would be reformatted. Also, the inList[4] was a typo, Finally, here's what I meant to post:
              @ QString s1, s2, s3, s4, sAll;
              s1 = QString(“ECG I”);
              s2 = QString(“ECG”);
              s3 = QString(“DISPLAY_WAVEFORM”);
              s4 = QString(“0”);
              QStringList l1;
              l1 << s1 << s2 << s3 << s4;
              sAll = QString(”%1 %2 %3 %4”)
              .arg(inList[0]).arg(inList[1]).arg(inList[2]).arg(inList[3]);

              SEGMENTATION FAULT – index out of range
              @
              Simply change the string DISPLAY_WAVEFORM to something like “word” and the problem goes away
              I have a little project all tarballed and ready to emal if anybody wants it[/quote]

              So, what is inList?

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              0
              • S Offline
                S Offline
                steveheflin
                wrote on last edited by
                #7

                Please see my edits. I changed the l1 to inList. I goofed up the original post trying to transcribe from my original code and shorten the variable names for the post. Sorry... all fixed now.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #8

                  What compiler and OS are you using?

                  @
                  #include <QStringList>
                  #include <QDebug>

                  int main(int argc, char *argv[])
                  {
                  QString s1, s2, s3, s4, sAll;
                  s1 = QString("ECG I");
                  s2 = QString("ECG");
                  s3 = QString("DISPLAY_WAVEFORM");
                  s4 = QString("0");
                  QStringList inList;
                  inList << s1 << s2 << s3 << s4;
                  sAll = QString("%1 %2 %3 %4")
                  .arg(inList[0]).arg(inList[1]).arg(inList[2]).arg(inList[3]);
                  qDebug() << inList;
                  return 0;
                  }
                  @

                  Above you find your little example after all our iterations as a complete program for compilation. It did run under msvc2005 without a problem. Check it out in your environment and see, if there is an issue.
                  If it still has the problem, you need to file a bug report on "JIRA":https://bugreports.qt-project.org/secure/Dashboard.jspa

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    stereomatching
                    wrote on last edited by
                    #9

                    The codes of koahnig work normally for me.

                    My os : windows 7 64bits
                    compiler : mingw 4.6.2
                    Qt : 4.8.2

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      steveheflin
                      wrote on last edited by
                      #10

                      The problem no longer appears either because of your iterations or my chopping of the example of bug. Please try my example project and you'll see the bug. It happens under Linux Fedora-16 (x86_64) as well as Windows-7-x86_64 using the latest version of MinGW.
                      @
                      http://www.newagemicro.com/test/QStringListBug.tgz
                      @

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        koahnig
                        wrote on last edited by
                        #11

                        [quote author="steveheflin" date="1345395747"]The problem no longer appears either because of your iterations or my chopping of the example of bug. Please try my example project and you'll see the bug. It happens under Linux Fedora-16 (x86_64) as well as Windows-7-x86_64 using the latest version of MinGW.
                        @
                        http://www.newagemicro.com/test/QStringListBug.tgz
                        @[/quote]
                        I believe you right away that the program you supply is crashing.
                        [quote author="stereomatching" date="1345377410"]QStringList start from index 0, end by index 3 if you only append 4 QString into it
                        0, 1, 2, 3[/quote]
                        It has still the index problem as pointed out in the quote above. I do not have to start the compiler for this.

                        Vote the answer(s) that helped you to solve your issue(s)

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          steveheflin
                          wrote on last edited by
                          #12

                          Yikes! I sure am having a heck of time showing the bug that my large application revealed! If you change the indexes (which I've done and reposted it), you will see that there is still a problem. It doesn't reproduce the Segmentation Fault that happens in my application, but it does show there is a problem because the merged strings don't appear in the edit box.

                          thanks for your help,
                          Steve

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            stereomatching
                            wrote on last edited by
                            #13

                            I have no problem about it
                            bq. because the merged strings don’t appear in the edit box.

                            Because it is a local variable
                            @
                            void MainWindow::CombineThem(QStringList inList)
                            {
                            QString sAll; //local variable, this variable "hide" the private sAll
                            sAll = QString("%1 %2 %3 %4").arg(inList[0]).arg(inList[1]).arg(inList[2]).arg(inList[3]);
                            }
                            @

                            change it to
                            @
                            void MainWindow::CombineThem(QStringList inList)
                            {
                            sAll = QString("%1 %2 %3 %4").arg(inList[0]).arg(inList[1]).arg(inList[2]).arg(inList[3]);
                            }
                            @

                            then you will see the text appear

                            This is more like a problem of C++ more than a problem of Qt

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              steveheflin
                              wrote on last edited by
                              #14

                              Thank you very much for your help. I attempted to demonstrate a bug I discovered, and in my haste ended up creating a buggy little program. I should have known that a bug in Qt4 is much more complex than my dinky little example. The real problem has to do with using QtXML in conjunction with QStringList and QTableWidget. I'll do a better job of carving out a real example of the problem from my application.

                              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