Jacob
asked on
Traversing thru directory structure for files
Hello experts.
I started C++ with Qt two days ago, and I am stock in trying to traverse thru my directory structure for MP3 files. I have found something and worked a little on that, I now have this;
As you see the code only find the files in that specific given directory, it does'nt go thru the structure what is what I want.
Can anyone help me further with this, thank you!
Jacob
I started C++ with Qt two days ago, and I am stock in trying to traverse thru my directory structure for MP3 files. I have found something and worked a little on that, I now have this;
void tjekdir(){
QDir dir;
dir.setPath("/home/you/Music/Some Artist");
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Dirs);
dir.setSorting(QDir::Size | QDir::Reversed);
QFileInfoList list = dir.entryInfoList();
std::cout << " Extension Path Bytes" << std::endl;
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
std::cout << qPrintable(QString("%1 %2 %3")
.arg(fileInfo.suffix())
.arg(fileInfo.absoluteFilePath())
.arg(fileInfo.size(), 10));
std::cout << std::endl;
}
}
As you see the code only find the files in that specific given directory, it does'nt go thru the structure what is what I want.
Can anyone help me further with this, thank you!
Jacob
ASKER
Hello, thanks for your suggestion,
I get an error at the line here: QDirIterator it(dir, QStringList() << "*.mp3", QDir::Files, QDirIterator::Subdirectori es);
This error message:
no matching function for call to 'QDirIterator::QDirIterato r(QDir&, QStringList&, QDir::Filter, QDirIterator::IteratorFlag )'
QDirIterator it(dir, QStringList() << "*.mp3", QDir::Files, QDirIterator::Subdirectori es);
I am not sure why, or what to do..
What can I do?
I get an error at the line here: QDirIterator it(dir, QStringList() << "*.mp3", QDir::Files, QDirIterator::Subdirectori
This error message:
no matching function for call to 'QDirIterator::QDirIterato
QDirIterator it(dir, QStringList() << "*.mp3", QDir::Files, QDirIterator::Subdirectori
I am not sure why, or what to do..
What can I do?
Have you included #include <QDirIterator>?
Also which version of Qt are you using?
Also which version of Qt are you using?
ASKER
Yes I have added the #include
I have Qt Creator 3.5.1
I have Qt Creator 3.5.1
Can you please write below code and let me know the Qt version?
qDebug() << QT_VERSION_STR;
Qt creator version doesn't help.
qDebug() << QT_VERSION_STR;
Qt creator version doesn't help.
ASKER
it says
5.5.1
5.5.1
Also can you please navigate to the the header file QDirIterator (go to the source of QDirIterator header file) and let me know what constructors does it have? Also does the compilation error message more than saying no match, does it say what could be the possible candidates?
Give me few minutes, I shall send you a working code with inline comments.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay. Thankyou. I got it working. Nice of you to give me two choices. I hope we will meet again, here on this site..
Thanks.!
Jacob
Thanks.!
Jacob
Glad I was of some help. Thanks, and you are welcome.
Something like below should work for you :
QDirIterator it(dir, QStringList() << "*.mp3", QDir::Files, QDirIterator::Subdirectori
while (it.hasNext()) {
qDebug() << it.next();
}
http://doc.qt.io/qt-5/qdiriterator.html