Convert qint64 to QString

With other types, I could easily do something like

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

Is there a similar function to turn 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 commented out a line that breaks the code. I had the same issue with a date, but used toString to convert it. I was hoping there would be the same solution for qint64.

+6
source share
3 answers

To do this, you need to write the following code:

 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("]"); 

For more information, see the documentation of the static methods QString::number(...) , starting here . You will need an option corresponding to qint64, which is a qlonglong override.

+4
source

Perhaps you are looking for QString::number(qlonglong, int) .

+7
source

A more general answer, because many people try 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 
+3
source

Source: https://habr.com/ru/post/954537/


All Articles