Results 1 to 5 of 5

Thread: problem clear QStringList

  1. #1
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default problem clear QStringList

    Hi!
    I need to clear the velf to show only inserted into the first "for".
    when compile and launching program occurs: Segmentation fault.

    Qt Code:
    1. int i = 0;
    2. while (i < list.size()){
    3. if (i <= -1)
    4. break;
    5. if (list.at(i).contains("SPNT",Qt::CaseSensitive)){
    6. qDebug() << "SPNT: " << list.at(i);
    7. i+=1;
    8. }else{
    9. for (int j = i+1, k = 0; j < list.indexOf("SPNT",i); ++j, ++k){
    10. velf.insert(k, list.at(j)); //velf[k] = list[j]; thus also occurs error
    11. }
    12. for (int i = 0; i < velf.size(); ++i)
    13. qDebug() << "VELF: " << velf.at(i);
    14. velf.clear();
    15. i = list.indexOf("SPNT",i);
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    Somebody has any idea?
    Thanks.
    Last edited by jaca; 29th May 2008 at 21:55.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem clear QStringList

    What is "i" in the first section of code?

  3. #3
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem clear QStringList

    Quote Originally Posted by wysota View Post
    What is "i" in the first section of code?
    I edited the post above.
    I tried to append, but the QStringList velf still add items.
    Last edited by jaca; 29th May 2008 at 22:10.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem clear QStringList

    If you use insert(), it doesn't overwrite existing items but creates new ones and moves the existing ones. If you want to overwrite items, use the operator[], just make sure you pass valid indices. In your case j points past the end of the list, hence the segfault.

    Oh, and get rid of indexOf() from the condition of the for loop. Instead save the value in a separate variable before the loop and use its value instead (in the second for parameter).

  5. #5
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    61
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem clear QStringList

    I am sending two archives. Just compile main.cpp. The RON09_posprt.txt archive contains a format that I want to modify. I must is thinking a wrong algorithm.
    to execute it makes:
    ./focus2anp LINE RON09_posprt.txt result.txt

    Can anyone help me improve this algorithm?
    Thanks.
    Attached Files Attached Files
    Last edited by jaca; 30th May 2008 at 18:34.

Similar Threads

  1. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  2. QStringList scope problem
    By ht1 in forum Qt Programming
    Replies: 5
    Last Post: 30th November 2007, 19:44
  3. svn problem: help me clear the repository
    By magland in forum General Discussion
    Replies: 1
    Last Post: 26th September 2007, 01:54
  4. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 17:01
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.