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
2
votes
1 answer

How to fix QFile open error (unknown error) even though the file exists?

I am trying to open and read a map.dat file using QFile interface, but it won't open that file even though it does exist in the directory. I have tried fopen, ifstream in C++, but they keep telling me the file does not exist even I have added it…
zcylywde
  • 23
  • 4
2
votes
2 answers

Qt copy file with sudo right

I handle the normal copying of files with Qt like this: QFile::copy("/path/file", "/path/copy-of-file"); How can I now copy a file for which Sudo rights are required.
Sonya
  • 53
  • 5
2
votes
1 answer

How to get a windows HANDLE from a QFile or QSaveFile for ReOpenFile?

Given a QFileDevice instance (a QFile, or QSaveFile) - how would one get the native Windows HANDLE of the file? And can this handle be used with ReOpenFile?
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
2
votes
1 answer

Qt: Writing umlaut to file

I am trying to store the contents of a QDomDocument to a file. The document contains a German umlaut, which doesn't get saved to the file correctly. My QDomDocument "document" is structured like this:
Don Joe
  • 274
  • 4
  • 13
2
votes
1 answer

How to report progress without going through the entire file before I process

I have to parse a big file with several thousand records. I want to display a progress bar, but I do not know the number of recordings in advance. Do I have to roll over this file twice? The first to know the number of recording. The second to…
kontiki
  • 186
  • 3
  • 16
2
votes
2 answers

How to check the available free space of a selected drive in Qt?

I am using Qt5.6.2 in Windows 7.My Goal is to save a CustomDatafile to a selected drive (mostly a Pen drive or local drive or network drive). So before saving the file I would like to check the available memory and write access of the selected…
vishnu
  • 363
  • 3
  • 20
2
votes
2 answers

QFile.open fails to open a file inside resource qrc

I have encountered a strange issue where QFile.open is unable to open a file which is added in the qrc resource file. My qrc file looks like this I'm using following code to read the file theme_normal.qss QFile…
warunanc
  • 2,221
  • 1
  • 23
  • 40
2
votes
1 answer

Qt: empty content of opened QFile for a .txt file from the project resources

I tried this in my project in mainwindow.cpp: QString dir = ":/nodesDir/nodesDir/"; QFile baseFile(dir + "allNodeNames.txt"); qDebug() << baseFile.exists(); // true qDebug() << baseFile.readAll(); // "" but it is wrong, the content of the file…
mep
  • 341
  • 2
  • 11
2
votes
1 answer

C++ / Qt - Cannot Open .txt from qrc file

I tryed a lot of things but they didnt work. I'm using Qt 5.9.1 and i wouldlike to open a .txt file (which is in a qrc file) in a QFile variable, like this : QFile file(":/txt/config"); I also tried to use QFile file("qrc:/txt/config");  Here's…
NicoTine
  • 51
  • 3
  • 12
2
votes
1 answer

Does QFile.open() behave like Python's with open() in terms of context management?

The Qt4.8 documentation (as mentioned here) suggests that a QtCore.QFile-object closes its file upon destruction (if the file is open). Does that mean that this PyQt4 snippet my_file =…
djvg
  • 11,722
  • 5
  • 72
  • 103
2
votes
2 answers

Writing an entire array to QFile

The QFile::write() documentation says: Writes at most maxSize bytes of data from data to the device. Returns the number of bytes that were actually written, or -1 if an error occurred. (Yes that's the entire documentation - unusually poor for…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
2
votes
3 answers

QT - QFile copy operation extremely slow

I'm developing an application that needs to copy lots of files from one folder to another, using QT (5.6.1) For doing this, I've been using the QFile::copy() method. This works well, except for one thing: it is extremely slow. Takes more than twice…
Master_T
  • 7,232
  • 11
  • 72
  • 144
2
votes
1 answer

Proper way to Copy files usign QT with GUI avoiding freeze

I have an application that copy files from one location to another, using QFile::Copy(..). The copy process is executed in a separated thread into a worker object, however, sometimes the GUI freezes, I have read a lot of topics here about this, but…
GTRONICK
  • 366
  • 4
  • 14
2
votes
1 answer

QFile::copy returns true even though copy failed in Windows

I have QString variable named "src", which holds a filename. Operation QFile::copy(src, target) works Ok, until target is "C:" or "C:/" (I have the problem in Windows 10). In this case the operation returns true, even though I do not see any files…
Maximko
  • 627
  • 8
  • 20
2
votes
3 answers

get file address without file name from QFile

I have a Qfile with fileName="d://f1/f2/img.jpg". I just want the address of the file ("d://f1/f2). How can I get it without converting to a QfileInfo?
mjyazdani
  • 2,110
  • 6
  • 33
  • 64