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.

284 questions
23
votes
2 answers

How to create a new File with full path in Qt?

I am a Qt beginner and just got stuck with the problem. I am looking for a file SomePath/NewDirectoryA/NewFile.kml (NewFile.kml will be the only file in NewDirectoryA, having this directory just to maintain semantics in the project). If…
GG.
  • 2,537
  • 5
  • 23
  • 32
18
votes
1 answer

Open QFile for appending

How can I open a QFile for appending, i.e. the equivalent of FILE *f = fopen("myfile.txt", "a");
sashoalm
  • 63,456
  • 96
  • 348
  • 677
16
votes
6 answers

Parsing through a csv file in Qt

Is anyone familiar with how to parse through a csv file and put it inside a string list. Right now I am taking the entire csv file and putting into the string list. I am trying to figure out if there is a way to get only the first column. #include…
user3878223
  • 401
  • 3
  • 7
  • 15
10
votes
2 answers

Qt: check if a file in folder is changed

There any way to trigger an action if a file in a specified directory ( or in a subfolder ) without fetching all modification times every time ? I'm asking because i've to check this live
Lwyrn
  • 1,600
  • 1
  • 12
  • 25
8
votes
3 answers

Progress bar with QFile::copy()?

I'm making a program which copies files in Qt. I want to know how can I use QProgressBar with bool QFile::copy(const QString & fileName, const QString & newName). Is this even possible with copy function? Can the process of copying be paused?
Amol Borkar
  • 1,209
  • 3
  • 21
  • 44
7
votes
3 answers

Convert QFile to FILE*

Is there another way to convet QFile to File? Different than this: QFile myFile("goforward.raw"); int FileDescriptor = myFile.handle(); FILE* fh = fdopen(FileDescriptor, "rb");
Jjreina
  • 2,393
  • 5
  • 28
  • 52
7
votes
2 answers

Overwrite text file vs append

I'm looking to overwrite data in a text file but all I can seem to do is append to it mFile.open(QFile::ReadWrite) QTextStream in(&mFile); QString first = in.readLine(); //discard the headers QString dataLine = in.readLine(); //headers QStringList…
Matt Stokes
  • 3,762
  • 9
  • 23
  • 45
7
votes
2 answers

Open file exclusively/lock file

I want to lock an existing file to prevent usage (read and write) from another process. That is, any subsequent attempt to open the file by this process or any other process should fail with an 'access denied' error. The CreateFile WINAPI function…
fpdragon
  • 1,785
  • 3
  • 22
  • 36
6
votes
2 answers

How to move a file to another existing directory in Qt

I am a beginner in Qt, one part of my project is moving a existing file to another existing directory? Can someone gives me a specific example? I am not sure whether I should use Qfile::rename(). I try write like…
innocent boy
  • 173
  • 2
  • 12
6
votes
4 answers

Why can't QFile read from the "~" directory?

I've tried the following short example to find out about a bug in a bigger program I am working on. It looks like QFile doesn't support unix (or the shell's) notation for the home directory: #include #include int main() { …
hurikhan77
  • 5,688
  • 3
  • 29
  • 46
6
votes
1 answer

QFile::remove not removing file?

Having a strange problem when trying to remove a file i just downloaded with Qt. My code: QString location = "/path/to/app/Application.app"; QFile *rmFile = new QFile(location); rmFile->remove(); File is not being removed. Any ideas what could be…
user3490755
  • 795
  • 2
  • 12
  • 29
6
votes
1 answer

Qt Streaming Large File via HTTP and Flushing to eMMC Flash

I'm streaming a large file ( 1Gb ) via HTTP to my server in Qt on a very memory constrained embedded Linux device. When I first receive the header I determine where to write the data on the filesystem, create a QFile pointer to that location, and…
PhilBot
  • 1,344
  • 17
  • 70
  • 143
5
votes
1 answer

Can I detect the pre-existance of a QFile after opening it in read/write/append mode?

I want to write some text to a file with a randomly chosen filename, but want to require that the file doesn't exist yet. There's a race-condition between a simple QFile::exists check followed by an open with the checked name. What's the best way…
Johannes Schaub - litb
  • 466,055
  • 116
  • 851
  • 1,175
5
votes
1 answer

Writing text in QFile

Is there any differences in two ways of writing text in QFile? By using write method: QFile file("test.txt"); if(file.open(QIODevice::WriteOnly | QIODevice::Text)) { file.write("My Text\n"); } file.close(); Or by using QTextStream: QFile…
Alexshev92
  • 161
  • 2
  • 6
5
votes
3 answers

Qt cannot cannot create/write to C:\

I am writing a Qt program (4.7 for windows 7 initially) that requires writing to the installed directory (C:\Program Files...). No files are being created when I try to write to a location that would be "protected" (program files, C:\ etc). However,…
jecjackal
  • 1,277
  • 2
  • 18
  • 34
1
2 3
18 19