QStringList bug - sensitive to content



  • 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



  • QStringList start from index 0, end by index 3 if you only append 4 QString into it
    0, 1, 2, 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


  • Moderators

    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



  • 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.


  • Moderators

    [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?



  • 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.


  • Moderators

    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



  • The codes of koahnig work normally for me.

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



  • 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
    @


  • Moderators

    [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.



  • 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



  • 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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.