View Full Version : QStringList problem :/
hakermania
17th August 2010, 11:57
See how it goes, I have a pushButton and a lineEdit. When the pushbutton is clicked a FileDialog::getOpenFileNames pop-ups, then I want to put the files selected into the lineEdit:
path = QFileDialog::getOpenFileNames(this, tr("Files & Directories"), QDir::currentPath(), tr("All files *.*") );
int x = path.length();
// ui->lineEdit_6->setText(path[x] + ", " + path[x-1); ?????????
I have the number of files selected but idk exactly how to put them into the lineedit...:(
Zlatomir
17th August 2010, 12:06
deleted QStringList has operator[]
You should use iterators to iterate the list of strings
Or add the whole list into a string (with the delimiter you want), using join() (http://doc.trolltech.com/latest/qstringlist.html#join) and then use that string to setText in the lineEdit.
Lykurg
17th August 2010, 12:16
QStringList does not have the operator[]
It has: QStringList = QList<QString> => QList::operator[].
But I would prefere at() or value(). And in your case the suggested join() should be perfect.
Zlatomir
17th August 2010, 12:26
@Lykurg: Thanks for correction, i'm used to c++ list (linked list) and keep forgetting that QList is implemented differently than QLinkedList (witch doesn't have [])
hakermania
17th August 2010, 12:59
So, join() appends QStrings?
How do I use it?
Lykurg
17th August 2010, 13:12
How do I use it?By reading the documentation or simply try?
aamer4yu
17th August 2010, 13:13
See - QStringList::join
hakermania
17th August 2010, 13:43
QString l = "";
path.join(l + ", ");
ui->lineEdit_6->setText(l);
doesn't workkkkkkkk
I am a beginner actually...:(:(
Can you help me on this?
bepaald
17th August 2010, 13:47
I haven't tried it out, but reading the doc, I think you need to do:
QString l = path.join(", ");
ui->lineEdit_6->setText(l);
See if that works.
bepaald
hakermania
17th August 2010, 13:55
I haven't tried it out, but reading the doc, I think you need to do:
QString l = path.join(", ");
ui->lineEdit_6->setText(l);
See if that works.
bepaald
Yep, thank you!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.