Results 1 to 9 of 9

Thread: how to split the text in Qstringlist

  1. #1
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to split the text in Qstringlist

    am having QStringlist
    QDir loggingDir(filenamepath);//this filename path conatins list of images
    QStringList dirList =loggingDir.entryList(QDir::Files,QDir::Time);
    nw inside dirlist
    ("IMG_6943.JPG", "IMG_6921.JPG", "IMG_6920.JPG", "pondy office-new.jpg", "20141117_161630.jpg", "20141117_161454.jpg", "team.jpg", "IMG_0394.JPG", "IMG_0393.JPG", "IMG_0391.JPG", "IMG_2711.JPG", "IMG_2709.JPG", "IMG_2483.JPG", "IMG_2478.JPG", "20130830_144720.jpg", "20130830_144520.jpg", "20130830_125724_LLS.jpg", "IMG_2305.JPG", "IMG_2304.JPG", "IMG_20130813_160214.jpg", "IMG_20130813_160127.jpg")
    i want to split these set of images to one by one to display images..can any one give suggestion for this,
    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to split the text in Qstringlist

    You already have a list, one file per list entry.
    Do you want to split each filename?

    Cheers,
    _

  3. #3
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to split the text in Qstringlist

    Quote Originally Posted by anda_skoa View Post
    You already have a list, one file per list entry.
    Do you want to split each filename?

    Cheers,
    _
    yes sir i want to split each filename

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

    Default Re: how to split the text in Qstringlist

    Split each filename according to what criteria?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,136
    Thanks
    294
    Thanked 851 Times in 838 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to split the text in Qstringlist

    Split each filename according to what criteria?
    I think you and the OP are interpreting the word "split" differently. If he wants to display each file in the list, then it makes no sense at all to split the file names into smaller pieces.

    I think he just doesn't understand how to retrieve the individual file names from the list.

    Qt Code:
    1. QString fileName;
    2. foreach( fileName, dirList )
    3. {
    4. // "fileName" now contains the name of one of the files in the list
    5. // Use QPixmap to read the image from the file
    6. // Use QLabel::setPixmap() to display the pixmap on a QLabel (for example)
    7. // or use QGraphicsPixmapItem to show it in a QGraphicsScene (for example)
    8. }
    To copy to clipboard, switch view to plain text mode 

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

    iswaryasenthilkumar (16th February 2015)

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

    Default Re: how to split the text in Qstringlist

    Quote Originally Posted by d_stranz View Post
    If he wants to display each file in the list, then it makes no sense at all to split the file names into smaller pieces.
    Yeah, I know, that's why I'm asking

    I think he just doesn't understand how to retrieve the individual file names from the list.
    If that's the case then I think retrieving the file name is the least of his problems
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to split the text in Qstringlist

    Quote Originally Posted by d_stranz View Post
    Qt Code:
    1. QString fileName;
    2. foreach( fileName, dirList )
    3. {
    4. // "fileName" now contains the name of one of the files in the list
    5. // Use QPixmap to read the image from the file
    6. // Use QLabel::setPixmap() to display the pixmap on a QLabel (for example)
    7. // or use QGraphicsPixmapItem to show it in a QGraphicsScene (for example)
    8. }
    To copy to clipboard, switch view to plain text mode 
    Just for the record, this is not a good idea.

    1) Having the loop variable outside the loop makes it much harder for the compiler to do any loop optimization, because its life time exceeds that of the loop

    2) Having a non-const ref loop variable means each loop iteration copies the list element. Inexpensive for a ref-counted type like QString but still unnecessary.
    Even for a ref-counted class it could lead to a deep-copy if any of the variable type's non-const method is called, even if there is a const variant, e.g. operator[]

    So for the example of a string list the way to write that foreach is
    Qt Code:
    1. foreach ( const QString &fileName, dirList )
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    iswaryasenthilkumar (16th February 2015)

  10. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,136
    Thanks
    294
    Thanked 851 Times in 838 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to split the text in Qstringlist

    I never use foreach() anyway, so I'm not that familiar with the syntax. I'm a QStringList::const_iterator type myself, in which case I would extract the filename to a const QString reference inside the iterator loop.

    But as wysota says...

  11. The following user says thank you to d_stranz for this useful post:

    iswaryasenthilkumar (16th February 2015)

  12. #9
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to split the text in Qstringlist

    thank you all i got answer based on all your tips i used QStringList:ir.entryList
    Thank you all

Similar Threads

  1. Replies: 7
    Last Post: 6th February 2017, 19:10
  2. Memory used to store text in QStringList.
    By jesse_mark in forum Qt Programming
    Replies: 6
    Last Post: 25th August 2014, 07:46
  3. Split string
    By mero in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2011, 19:17
  4. split a QTabWidget?
    By shud in forum Qt Programming
    Replies: 1
    Last Post: 15th July 2009, 19:56
  5. Replies: 7
    Last Post: 2nd June 2006, 12:48

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.