Thank you very much, Jon and SGaist, I really appreciate your help and I learned something fundamental :-)
I followed your instructions and here is the now working code: (just in case another newbie is stuck with the tutorial "Using model indexes")
// myslot.h
#ifndef MYSLOT_H
#define MYSLOT_H
#include <QDebug>
#include <QFileSystemModel>
#include <QModelIndex>
class MySlot : public QObject
{
Q_OBJECT
public:
explicit MySlot(QObject *parent) : QObject(parent) {}
void setModel(QFileSystemModel* model);
public slots:
void printDirectory(const QString);
private:
QFileSystemModel* m_model;
};
#endif // MYSLOT_H
// myslot.cpp
#include "myslot.h"
void MySlot::setModel(QFileSystemModel *model)
{
m_model = model;
Object::connect(model,SIGNAL(directoryLoaded(QString)),this,SLOT(printDirectory(QString)));
}
void MySlot::printDirectory(const QString dir)
{
QModelIndex parentIndex = m_model->index(dir);
int numRows = m_model->rowCount(parentIndex);
// qDebug() << numRows;
for (int row = 0; row < numRows; ++row) {
QModelIndex index = m_model->index(row, 0, parentIndex);
QString text = m_model->data(index, Qt::DisplayRole).toString();
// Display the text in a widget.
qDebug() << text;
}
}
// main.cpp
#include <QApplication>
#include <QFileSystemModel>
#include <QModelIndex>
#include "myslot.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFileSystemModel* model = new QFileSystemModel;
model->setRootPath(QDir::currentPath());
MySlot* myslot = new MySlot(NULL);
myslot->setModel(model);
return app.exec();
}
Output is a list of all files and folders in the current path.
Thanks again for your kind support, I couldn't have done it without your help!