Questions tagged [qfile]

A QFile is a class from the Qt Toolkit which provides an interface for reading from and writing to files.

QFile is an I/O device for reading and writing text and binary files and resources. A QFile may be used by itself or, more conveniently, with a QTextStream or QDataStream.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

305 questions
3
votes
2 answers

QFile won't open the file

I have a program that I basically stole from the Qt website to try to get a file to open. The program refuses to open anything I am confused as to why. I have looked for lots of documentation but found nothing can you please explain why it does not…
user1647753
3
votes
1 answer

Passing QFile to function

I get an illegal indirection error at generateCSVHeader(*file4);. function declaration: void generateCSVHeader(QFile * file); function use: str="MyData.csv"; QFile file4(str); generateCSVHeader(*file4); when I drop the dereference designator, it…
moesef
  • 4,641
  • 16
  • 51
  • 68
3
votes
1 answer

Best way to write a custom class to a file using qt

Hey all (out there :). Which way is the best for writing a custom class to a file in Qt? Thank you in advance. Matthias
Matthias -_-
  • 101
  • 1
  • 10
3
votes
1 answer

How to map a resource file in Qt?

Is it possible to map a resource file in Qt? For example: QFile file(resource_name); file.open(QIODevice::ReadOnly); uchar* ptr = file.map(0, file.size()); When I try this, ptr == 0, indicating an error. It works fine if I try to map a regular…
Karl Voigtland
  • 7,637
  • 34
  • 29
3
votes
2 answers

Qt, QFile write on specific line

I've run into another problem in Qt, I can't seem to figure out how to write on a specific line on a text file with QFile. Instead, everything is erased written at the beginning. So with the given information, how would I write to a specific line in…
Gabriel
  • 3,039
  • 6
  • 34
  • 44
2
votes
3 answers

QFile::QFile function --> Error: QFile :: QFile (const QFile &) 'is private

In one of my methods I need a QFile Object: void GUIsubclassKuehniGUI::LoadDirectory() { QString loadedDirectory = QFileDialog::getExistingDirectory(this, "/home",tr("Create…
Streight
  • 811
  • 4
  • 15
  • 28
2
votes
2 answers

Reverse text file writing in QT

How is it better to implement writing to QFile in reverse order, string by string. With use of seek(0) new string is written over old one.
Funt
  • 399
  • 8
  • 23
2
votes
1 answer

QFile class start of stram

I'm using Qt for reading binary file. I read file with QFile object, but sometimes I need to go back at begining of the file and read file again, but I don't know how to do that.
MrD
  • 2,423
  • 3
  • 33
  • 57
2
votes
1 answer

Recommended way of passing file paths in Qt application

in the codebase (C++ and Qt5) I am working on, filepaths are passed as QString parameters most of the time. In some cases it is also a combination of QDir and QString. Examples: void foo(const QString &filename); void foo(const QDir pathToFile,…
Christian
  • 31
  • 3
2
votes
2 answers

QFileInfo::exists() for a shared-drive file path

Question from a newcomer to QT: when I supply the exists() method of a QFileInfo object with a shared-drive file path, it always returns false, even with me escaping every backslash with another backslash (i.e. \\10.1.2.34.56\dir1). And yes, the…
Sheldon R.
  • 452
  • 2
  • 7
  • 26
2
votes
3 answers

How to get number of bytes from QFile?

I have this code: int *size1 = new int(); int *size2 = new int(); QFile* file = new QFile("C:/Temp/tf.txt"); file->open(QFile::WriteOnly | QFile::Truncate); file->write(str); *size1 = file->size(); file->close(); file->open(QFile::WriteOnly |…
tucnak
  • 33
  • 1
  • 2
  • 6
2
votes
1 answer

Qt: how to write/ append unicode data to an existing file

I have a file where I want to write/ append unicode data to, because it is already unicode data (created by WMIC file output). It starts with UTF-16 (LE) BOM: 0xFF 0xFE. I'd like to append some information in a loop: QString line =…
matthias
  • 247
  • 6
  • 17
2
votes
1 answer

Modify file's lastModified/lastAccessed/created date in Qt

I have an application that copies some files, but during the copy procedure, the last modified, etc dates are changed to the current date & time. On a few forums, I see it is suggested to use the SETFILETIME call from the fileapi.h as specified here…
CybeX
  • 2,060
  • 3
  • 48
  • 115
2
votes
1 answer

QVector::clear and QFile::close in QThreadPool

I am using QThreadPool to run a worker that has function to create then clear huge QVector and write huge size of file. However, every time one worker reach that lines (QVector::clear/QFile::close) all the threads got freeze and will continue when…
zufryy
  • 177
  • 2
  • 10
2
votes
1 answer

How to open a file in android with qt having the content URI

How do i open a file with QFile with link in android -content://com.android.providers.downloads.documents/document/raw.pdf I tried below code but its showing that the file not open QString…
Husni Abdul Nazer
  • 103
  • 1
  • 1
  • 12