I am using the file finder dialog example at https://doc.qt.io/archives/qt-4.8/qt...s-example.html
In the code they grab and display the size of the file. For me having the date is more helpful than having the size.
Here is the code that does it:
{
for (int i = 0; i < files.size(); ++i) {
QFile file(currentDir.
absoluteFilePath(files
[i
]));
fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
.arg(int((size + 1023) / 1024)));
sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable);
int row = filesTable->rowCount();
filesTable->insertRow(row);
filesTable->setItem(row, 0, fileNameItem);
filesTable->setItem(row, 1, sizeItem);
}
filesFoundLabel->setText(tr("%1 file(s) found").arg(files.size()) +
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
(" (Select file to open it)"));
#else
(" (Double click on a file to open it)"));
#endif
filesFoundLabel->setWordWrap(true);
}
void Window::showFiles(const QStringList &files)
{
for (int i = 0; i < files.size(); ++i) {
QFile file(currentDir.absoluteFilePath(files[i]));
qint64 size = QFileInfo(file).size();
QTableWidgetItem *fileNameItem = new QTableWidgetItem(files[i]);
fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("%1 KB")
.arg(int((size + 1023) / 1024)));
sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable);
int row = filesTable->rowCount();
filesTable->insertRow(row);
filesTable->setItem(row, 0, fileNameItem);
filesTable->setItem(row, 1, sizeItem);
}
filesFoundLabel->setText(tr("%1 file(s) found").arg(files.size()) +
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
(" (Select file to open it)"));
#else
(" (Double click on a file to open it)"));
#endif
filesFoundLabel->setWordWrap(true);
}
To copy to clipboard, switch view to plain text mode
I can't find info on what is in the list when the line
filesTable->setItem(row, 1, sizeItem);
is executed.
Thanks for any help
emp1953
Added after 12 minutes:
I found it in the QFileInfo class the function is .lastModified() It returns a QDateTime.
but now I can't get that time date to print in the file dialog box, first I'd like to format it so its just mm/dd/yyyy, then I want it in the dialog box
I added
QDateTime fdate = (files).lastModified();
qDebug() << fdate.toString();
I changed:
QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("%1 KB")
.arg(int((size + 1023) / 1024)));
to:
QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("")
.arg(QString(files)));
Compiles and prints all the dates & times correctly for all of the files found.
I can't get it to print in the dialog box.
Bookmarks