PDA

View Full Version : how to split the text in Qstringlist



iswaryasenthilkumar
13th February 2015, 12:17
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,:confused:
Thanks in advance:o

anda_skoa
13th February 2015, 12:26
You already have a list, one file per list entry.
Do you want to split each filename?

Cheers,
_

iswaryasenthilkumar
13th February 2015, 12:29
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

wysota
13th February 2015, 15:52
Split each filename according to what criteria?

d_stranz
13th February 2015, 16:26
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.



QString fileName;
foreach( fileName, dirList )
{
// "fileName" now contains the name of one of the files in the list
// Use QPixmap to read the image from the file
// Use QLabel::setPixmap() to display the pixmap on a QLabel (for example)
// or use QGraphicsPixmapItem to show it in a QGraphicsScene (for example)
}

wysota
13th February 2015, 17:19
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 :)

anda_skoa
14th February 2015, 07:53
QString fileName;
foreach( fileName, dirList )
{
// "fileName" now contains the name of one of the files in the list
// Use QPixmap to read the image from the file
// Use QLabel::setPixmap() to display the pixmap on a QLabel (for example)
// or use QGraphicsPixmapItem to show it in a QGraphicsScene (for example)
}

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


foreach ( const QString &fileName, dirList )
{
}


Cheers,
_

d_stranz
15th February 2015, 01:36
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...

iswaryasenthilkumar
16th February 2015, 05:37
thank you all i got answer based on all your tips i used QStringList::Dir.entryList
Thank you all