O
O
Oleg Seledets2019-04-21 09:57:44
Qt
Oleg Seledets, 2019-04-21 09:57:44

How to get file size?

Hello, I'm trying to get the file size in this way:

qint64 labor::fileSizer(QString nameRar)
{
    qint64 fileSize=0;
    QFile fileRar("C:\\QtProject\\modulINFO\\temp\\lab\\lab2\\"+nameRar+".rar");
    fileRar.open(QIODevice::ReadOnly);
    fileSize = fileRar.size();
    fileRar.close();
    return  fileSize;
}

ui->label_2->setText(QString::number(fileSizer("test1")));

Returns always zero, regardless of the weight of the source file. what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2019-04-21
@oleja1ee7

1) make sure the file really exists. To do this, open returns a bool.
2) better use QFileInfo.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question