Re: How to change file info shown in qt examples
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:
Code:
{
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);
}
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.
Re: How to change file info shown in qt examples
Quote:
QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("").arg(QString(files)));
Should be:
The "%1" is required and tells QString to put the value returned by the arg() call in place of the %1. If you wanted to place multiple values in a formatted string, you would write something like:
And if what you want to put in the second column is the date, you would obviously not want to pass a QStringList (which is what "files" is), but instead a QString formatted to contain the date for files[i]. You have already done this for your QDebug statement.