Results 1 to 5 of 5

Thread: position of an item in a QStringList

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

    Default position of an item in a QStringList

    Hi!

    I have the following:
    Qt Code:
    1. //list == ["SPNT", "123", "321", "SPNT", "111", "122", "222", "211", "SPNT", "001", "SPNT"]
    To copy to clipboard, switch view to plain text mode 
    I wanted to know the position of each SPNT. I used list.indexOf ( "SPNT") but only returns the first position. How do I know the position of the string SPNT in QStringList?
    My idea is to print a file in the numbers between the SPNT this way:
    123 321
    111 122 222 211
    001

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: position of an item in a QStringList

    Did you notice the optional second parameter of indexOf()?
    J-P Nurmi

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

    Default Re: position of an item in a QStringList

    The position of SPNT change depending on the file. How do I set a start if I do not know where the SPNT will appear in another file?

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

    Default Re: position of an item in a QStringList

    Actually I have a file like this:

    SPNT 962
    570 1485 1364 1944 2176 2417 2986 2980
    3504 3362 4034 3745 4660 4176 5094 4489
    5344 4600 5730 4718 8090 4962
    SPNT 1122
    514 1485 672 1520 1652 2111 2176 2417
    2986 2980 3504 3362 4034 3745 4660 4176
    5032 4433 5370 4614 5730 4718 8090 4962
    SPNT 1282
    514 1485 672 1520 1652 2111 2184 2431
    2986 2980 3504 3362 4034 3745 4660 4176
    5032 4433 5298 4593 5914 4739 8090 4962
    SPNT
    ---------------------------------------------------------------------------------------------------------------------
    And I put it in this format:

    SPNT 962
    VELF 570 1485 1364 1944 2176 2417 2986 2980 3504 3362
    VELF 4034 3745 4660 4176 5094 4489 5344 4600 5730 4718
    VELF 8090 4962
    SPNT 1122
    VELF 514 1485 672 1520 1652 2111 2176 2417 2986 2980
    VELF 3504 3362 4034 3745 4660 4176 5032 4433 5370 4614
    VELF 5730 4718 8090 4962
    SPNT 1282
    VELF 514 1485 672 1520 1652 2111 2184 2431 2986 2980
    VELF 3504 3362 4034 3745 4660 4176 5032 4433 5298 4593
    VELF 5914 4739 8090 4962

    There must be an easier way that my.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: position of an item in a QStringList

    Quote Originally Posted by jaca View Post
    The position of SPNT change depending on the file. How do I set a start if I do not know where the SPNT will appear in another file?
    There are many ways to do that, really. Here's pseudo code to go through all the instances of 'SPNT' in a string list.
    Qt Code:
    1. from = 0
    2. index = 0
    3. while ( index = strlist.indexOf('SPNT', from) != -1 )
    4. ...
    5. from = index
    6. endwhile
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by jaca View Post
    Actually I have a file like this:
    ...
    And I put it in this format:
    ...
    There must be an easier way that my.
    Why don't you read it line by line and insert VELF in the beginning of line where the line doesn't start with SPNT?
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    jaca (29th May 2008)

Similar Threads

  1. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  2. QGraphicsView: Dialog Position Doubt
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2007, 17:48
  3. Replies: 1
    Last Post: 19th April 2007, 22:23
  4. How to get a position of the menu bar item?
    By Mad Max in forum Qt Programming
    Replies: 2
    Last Post: 20th November 2006, 03:20
  5. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 01:34

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.