Quote Originally Posted by jho View Post
I have three listWidgets where I need to add these three arrays.
It would be much better to have three listViews each serving a separate column from a single model based on QFileInfoList.

Something along the lines of:
Qt Code:
  1. #include <QtWidgets>
  2.  
  3. class InfoListModel : public QAbstractTableModel {
  4. public:
  5. InfoListModel(const QFileInfoList &list, QObject *parent = 0) : QAbstractTableModel(parent), m_data(list) {}
  6. int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : m_data.size(); }
  7. int columnCount(const QModelIndex &parent = QModelIndex()) const { return 3; }
  8. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const {
  9. if(!hasIndex(index.row(), index.column(), index.parent())) return QVariant();
  10. if(role != Qt::DisplayRole) return QVariant();
  11. const QFileInfo &finfo = m_data.at(index.row());
  12. switch(index.column()) {
  13. case 0: return finfo.fileName();
  14. case 1: return finfo.lastModified().toString("dd/MM/yyyy hh:mm:ss");
  15. case 2: return finfo.size();
  16. default: return QVariant();
  17. }
  18. }
  19. private:
  20. QFileInfoList m_data;
  21. };
  22.  
  23. int main(int argc, char **argv) {
  24. QApplication app(argc, argv);
  25. QFileInfoList list = QDir(argv[1]).entryInfoList(QDir::Files|QDir::NoDotAndDotDot);
  26. InfoListModel model(list);
  27. l1.setModel(&model);
  28. l2.setModel(&model);
  29. l3.setModel(&model);
  30. l1.setModelColumn(0);
  31. l2.setModelColumn(1);
  32. l3.setModelColumn(2);
  33. l1.show();
  34. l2.show();
  35. l3.show();
  36. return app.exec();
  37. }
To copy to clipboard, switch view to plain text mode 

And there is also QFileSystemModel.