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
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,407
  • 2
  • 20
  • 35
5
votes
1 answer

Does Qt auto close files?

One of the QIODevice reimplemented open() methods in QFile has a QFileDevice::FileHandleFlag argument. Taking a look at the documentation for it there are two options with contradicting descriptions. From the QFileDevice…
Itay Grudev
  • 7,055
  • 4
  • 54
  • 86
5
votes
2 answers

QFile open file for writing fails

I'm trying to open file and write some text data into it. QFile out(":/test.txt"); if (!out.open(QIODevice::ReadWrite)) { QMessageBox msgBox; msgBox.setText(out.errorString()); msgBox.exec(); return; } But it fails with "Unknown…
TermiT
  • 144
  • 1
  • 8
5
votes
3 answers

QFileInfo exists() and isFile() error

I'm trying to check if provided path exists and if it is a file. So I wrote this piece of code: #include #include bool Tool::checkPath(const QString &path){ QFileInfo fileInfo(QFile(path)); return (fileInfo.exists()…
Kousalik
  • 3,111
  • 3
  • 24
  • 46
5
votes
1 answer

Why does QFile::canReadLine() always return false?

I was trying to read a file line by line using while (file.canReadLine()) { QString line = QString::fromUtf8(file.readLine()); qDebug() << line; } but QFile::canReadLine() always returns false, even though file.readLine() succeeds and reads…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
5
votes
1 answer

Will QFile::copy create create a copy of the file or move the contents from one file to another?

I am trying to copy a file from one location to another( in a device) using C++/Qt I tried QFile::copy("path1/file","path2"); I want to copy the file in path1 to path2. path2 does not have the file. I just want to know if this is the right way…
user1065969
  • 589
  • 4
  • 10
  • 19
4
votes
1 answer

QFile. Device not open

I have problem with QFile. QFile file1("file1.dat"); QFile file2("file2.dat"); if(file2.exists()) { } if(!file1.open(QIODevice::ReadOnly)) { qDebug() << "Ошибка открытия для чтения"; } if(!file2.open(QIODevice::WriteOnly)) { qDebug() <<…
sardorkun
  • 87
  • 2
  • 11
4
votes
2 answers

Qt's QDir: File Names Dropping Non-Ascii Characters

I am having issues with QDir losing Non-Ascii characters from my file names. I have files with names like testingöäüß.txt or exampleΦ.shp and when trying to use Qt utilities like QDir and QFile they simply show up as testing.txt and example.shp.…
cheddarhead52
  • 61
  • 1
  • 4
4
votes
2 answers

Non-blocking worker - interrupt file copy

I'm dealing with very large files, in excess of hundreds of GB in size. The User needs to be able to move these files between disks and is on a restricted system with no default file manager. It's possible for the User to realize they've made a…
MildWolfie
  • 2,492
  • 1
  • 16
  • 27
4
votes
2 answers

How to reuse QFile?

I would like to save two files to a dir using the following code: QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), …
Nyaruko
  • 4,329
  • 9
  • 54
  • 105
4
votes
2 answers

QFile to QByteArray save file name

I have a QFile that needs to be sent through a LAN network. In order to do so, I convert the QFile into QByteArray by doing: //! [Inside a QTcpSocket class] // Get the file name using a QFileDialog QFile file(QFileDialog::getOpenFileName(NULL,…
Alex Spataru
  • 1,197
  • 4
  • 14
  • 26
4
votes
3 answers

Permanently delete file in Qt

I had to change the program on Qt that I did not write. I located the place in the code and know what I want it to, but I do not know what to change, so seek help. Code is as follows: QFile file(path); qint64 size = filesize(path); qint64…
user3497819
  • 41
  • 1
  • 2
4
votes
1 answer

File changes handle, QSocketNotifier disables due to invalid socket

I am developing for a touch screen and need to detect touch events to turn the screen back on. I am using Qt and sockets and have run into an interesting issue. Whenever my QSocketNotifier detects the event it sends me infinite notices about it.…
Fraunk
  • 61
  • 1
  • 5
3
votes
1 answer

Using iomanip to format data output to a text file with Qt

I am a student programmer using QT to develop and application for work. Currently I am developing the save functions in which data is taken from a table and saved to a file. Im running into some trouble when I try to write the data into columns. Not…
Wylie Coyote SG.
  • 1,009
  • 6
  • 22
  • 37
3
votes
1 answer

Does QFile::copy keep the source file permissions in the copied file?

I am trying to copy a game from a disk or USB flash drive to hard drive in my computer using Qt and I wanted to use QFile::copy and it is important for me to keep the permissions like being executable and writable. Do I have to use…
Amy jonas
  • 91
  • 6
1
2
3
20 21