Questions tagged [qiodevice]

The QIODevice class is the base interface class of all I/O devices in Qt.

The QIODevice class is the base interface class of all I/O devices in Qt.

QIODevice provides both a common implementation and an abstract interface for devices that support reading and writing of blocks of data, such as QFile, QBuffer and QTcpSocket. QIODevice is abstract and can not be instantiated, but it is common to use the interface it defines to provide device-independent I/O features. For example, Qt's XML classes operate on a QIODevice pointer, allowing them to be used with various devices (such as files and buffers).

Before accessing the device, open() must be called to set the correct OpenMode (such as ReadOnly or ReadWrite). You can then write to the device with write() or putChar(), and read by calling either read(), readLine(), or readAll(). Call close() when you are done with the device.

QIODevice distinguishes between two types of devices: random-access devices and sequential devices.

  • Random-access devices support seeking to arbitrary positions using seek(). The current position in the file is available by calling pos(). QFile and QBuffer are examples of random-access devices.
  • Sequential devices don't support seeking to arbitrary positions. The data must be read in one pass. The functions pos() and size() don't work for sequential devices. QTcpSocket and QProcess are examples of sequential devices.

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

60 questions
0
votes
0 answers

How to write multiple times to the child process from the several part of the parent code(QProcess)?

I'm a beginner in QT, and I'm trying to send/write some data from the parent process(C++) to the child process(python) and the child process need to receive that data. Parent code: if(PythonProcess.state() == QProcess::Running){ …
rohan099
  • 83
  • 1
  • 5
0
votes
0 answers

Why is my audio delay filter losing the delay?

I'm trying to stream audio from a QAudioInput to a QAudioOutput (Qt 5.15) but with a few seconds of artificial delay. In an effort to keep the code simple I implemented a delay filter based on a QIODevice, which sits between the input and output.…
Jason C
  • 38,729
  • 14
  • 126
  • 182
0
votes
1 answer

Qt cannot write to file. File exists, isn't open, "Unknown error" (Windows OS)

Would really appreciate your help. I'm new to Qt and C++. I managed to get this working previously, but for some reason am no longer able to do so. I haven't touched anything to do with the writing of files, but all functions pertaining to file…
Chris
  • 3
  • 2
0
votes
2 answers

How do I calculate the opimal size of the bytes to read from a file using QIODevice:read()?

The thing is, I have to read the file and write its data to another file. But the size might be so big (larger than 8 gb) so I read the files by chunks (1 mb), but I think the optimal size of the chunks can be calculated, so how do I do this? what…
Isidore
  • 27
  • 4
0
votes
1 answer

Using QSettings with data stored in a QByteArray, or QIODevice?

I have data in ini format that was originally written using QSettings (and so it contains some QSettings-specific syntax) that is stored in a QByteArray. I'd like to be able to read and write to it using QSettings. Unfortunately, out of the box…
Bri Bri
  • 2,169
  • 3
  • 19
  • 44
0
votes
0 answers

Why does Qt implement QFile::size() which returns a qint64 rather than quint64

So going through the QFile docs, I found QFile::size() returns a qint64. It would make sense (to me atleast) if QFile::size() returned an unsigned integer i.e. quint64 as file sizes range from 0 bytes and upwards. QFile::size() reimplements some…
CybeX
  • 2,060
  • 3
  • 48
  • 115
0
votes
1 answer

QIODevice::size() and QIODevice::bytesAvailable() always return 0

I'm writing an emulator that requires me to continuously push generated raw audio samples to a QAudioOutput. This is achieved by writing bytes to the underlying QIODevice like so: Qt_speaker::Qt_speaker() { QAudioFormat fmt; …
dav
  • 626
  • 4
  • 21
0
votes
1 answer

How to get 2D array from UART to QList Qt and set text on QML

I receive a 2D array from UART that sent from Arduino. I can show it in debug, but I can not save it in a QList variant to set text for matrix of rectangle in QML. I want to show text on QML each rectangle. How I can do? This is Arduino code. I send…
TrungPC
  • 57
  • 1
  • 7
0
votes
0 answers

Using QIODevice with anonymous pipes

I want to use a QIODevice in order to read from a unnamed pipe if data is available. I tried this with QFile: m_pFile_Pipe = new QFile(); HANDLE hRead, hWrite; connect(m_pFile_Pipe, SIGNAL(readyRead()), this,…
NTG
  • 73
  • 9
0
votes
1 answer

Why I can't reimplement methode from QIODevice when base class is QFile?

when my base class is QIODevice I can reimplement writeData and readData, but if the base class is QFile it doesn't work. The base class of OFile is QFileDevice and the base class of QFileDevice is QIODevice: //This works: //class xyseriesiodevice :…
0
votes
2 answers

QT and I/O Possible error

Please describe what the "I/O Possible" SIGIO error typically indicates, from a QT C++ prospective. I know I/O stands for Input/output, but that's about all I know. The only decent information I have found is:…
JavaBeast
  • 766
  • 3
  • 11
  • 28
0
votes
1 answer

Subclassing QIODevice: Wrapper for QUdpSocket

I am trying to implement my own wrapper over QUdpSocket because of it is uncomfortable to use. I can use it, but anyway I need to implement some intermediate buffer for access to QDataStream operations. In additional: I sublass QIODevice, header…
Vladimir Bershov
  • 2,701
  • 2
  • 21
  • 51
0
votes
0 answers

workaround for QTBUG-26538

I am developing an application that has to run on ubuntu 14.04, that bundles qt 5.2.1. I use QUdpSocket as QIODevice, so I first bind to a port where my server accept datagrams, then I call connectToHost(). Unfortunately I have to face with…
mastupristi
  • 1,240
  • 1
  • 13
  • 29
0
votes
0 answers

Pyqt4 QMovie FFMPEG decoder

I'm quite new to pyqt. So please forgive any misconcepts I might have. I have trouble to load video directly to QMovie using: __init__ (self, QString fileName, ...) QMovie itself seems quite picky when it comes to supporting (decoding) Video…
ljilekor
  • 31
  • 2
0
votes
1 answer

QtAV and cleaning of the buffer

I'm writing an application in Qt that permits the video streaming from a byte array. As video output component I'm using QtAV (http://www.qtav.org/). In my case the input of this component is a QIODevice (QBuffer) where has a QByteArray with my…