Question

With other types I could easily do something like

mitm.created().toString("yyyy-MM-dd")

Is there a similar function to turn a qint64 into a QString? You can find the code below.

    fileArray.append("[");
    foreach(QFileInfo mitm, mDir.entryInfoList(QDir::Files)){
        fileArray.append("{\"filePath\": \"");
        fileArray.append(mitm.absoluteFilePath());
        fileArray.append("\",");
        fileArray.append("\"fileCreated\": \"");
        fileArray.append(mitm.created().toString("yyyy-MM-dd"));
        fileArray.append("',");
        fileArray.append("'fileSize': '");
//      fileArray.append(mitm.size());
        fileArray.append("\"}");
        if(fileCount!=mDir.entryInfoList(QDir::Files).count()-1){ fileArray.append(","); }
        fileCount++;
    }
    fileArray.append("]");

I've commented out the line which breaks the code. I had the same problem with date but used toString to convert it. I was hoping there would be a similar solution for qint64.

Was it helpful?

Solution 3

You will need to write the following code for that:

fileArray.append("[");
foreach(QFileInfo mitm, mDir.entryInfoList(QDir::Files)){
    fileArray.append("{\"filePath\": \"");
    fileArray.append(mitm.absoluteFilePath());
    fileArray.append("\",");
    fileArray.append("\"fileCreated\": \"");
    fileArray.append(mitm.created().toString("yyyy-MM-dd"));
    fileArray.append("',");
    fileArray.append("'fileSize': '");
    fileArray.append(QString::number(mitm.size()));
    fileArray.append("\"}");
    if(fileCount!=mDir.entryInfoList(QDir::Files).count()-1){ fileArray.append(","); }
    fileCount++;
}
fileArray.append("]");

See the documentation of the QString::number(...) static methods for details, starting here. You will need the variant matching qint64 which is the qlonglong override.

OTHER TIPS

You are probably looking for QString::number(qlonglong, int).

More general reply, because a lot of people gets here trying to find the answer to the exact question in the title:

QDateTime lm = QFileInfo(QFile(current)).lastModified();
qint64 epoch = lm.toMSecsSinceEpoch();
QString str = QString::number(epoch); // actual conversion
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top