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

Custom URL protocol handler Qt 5

I want to use a Video/MediaPlayer QML element in my app, and have it play a video from a custom stream. QMediaPlayer seems to support this since you can tell it to read from a QIODevice which can do anything you want. But MediaPlayer only supports a…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
6
votes
1 answer

Qt: How to catch an error with system call?

I am building a GUI application where I do a system call and call for gnuplot to run a script. Now i want to build in an error message that says when something is wrong (e.g. gnuplot is not installed or in the wrong path). So I've been thinking…
Tcanarchy
  • 760
  • 1
  • 8
  • 20
5
votes
1 answer

Input video data from C++ to QML Video Player

I am looking for a best way to implement a video player application in QML. Almost all QML examples are reading files from filesystem or web: MediaPlayer { id: mediaplayer source: "groovy_video.mp4" } VideoOutput { anchors: parent.fill …
psyched
  • 1,859
  • 1
  • 21
  • 28
4
votes
1 answer

Is there an intra-process local pipe in Qt?

Does Qt have a QIODevice pair that would work for intra-process point-to-point communications? One could use the concrete QTCPSocket or QLocalSocket, but the server-side connection API is a bit cumbersome, and it seems wasteful to force the data…
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
4
votes
3 answers

how does readyRead() work in Qt?

It's my first question on this website ! I have some trouble reading datas from a COM port, I send a complete message from another COM port, and when I receive it with Qt, it's always cut in multiple submessages. void SerialPortReader::init() { …
palador
  • 273
  • 2
  • 3
  • 11
4
votes
2 answers

QSerialPort is causing a program stop (endless loop?) if opening device

I want to write on a serial device. Unfortunately I have the feeling the QSerialPort is not properly implemented under linux. In contrast to other methods (python) I get !sometimes! a hang of the program when I try to…
dgrat
  • 2,214
  • 4
  • 24
  • 46
3
votes
0 answers

How to determine that I am at the "end" of a QIODevice?

I am attempting to come up with an algorithm to detect when the "end" of a QIODevice is reached (meaning no more data will ever be available for reading). Currently, my algorithm looks something like this: for sequential devices, wait for the…
Nathan Osman
  • 71,149
  • 71
  • 256
  • 361
3
votes
1 answer

How to read POST data "sent" from my own QtWebKit application?

How can I read POST data "sent" from my own QtWebKit application? I am developing a small hybrid QWebKit application, which uses HTML forms for user input, than executes local Perl scripts and displays the final result. Nothing is actually sent to…
ddmitov
  • 31
  • 4
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
2
votes
2 answers

How to communicate Qt applications two-way

I want to create two-way communicate beetwen my Qt Apps. I want to use QProcess to do this. I'm calling sucesfully child app from root app and sending test data without any erro, but I can't recive any data in child app. I'll be gratefull for any…
kluszon
  • 375
  • 5
  • 19
2
votes
2 answers

How can I determine the total size of a QIODevice for read?

I'm using qt 5.3. I have a big thing written into a QIODevice for read. I want to have a proxy to get the data while keep the data in QIODevice available for the other thing to read. So if I call readAll() I will get everything good in proxy but the…
K--
  • 659
  • 1
  • 7
  • 18
2
votes
2 answers

QMediaplayer streaming from a custom QIODevice with encryption on Mac OS (10.9)

i'm currently porting an application from Qt4(.8.4) to Qt5(.2.0). I'm nearly done with all the known changes like deprecated toAscii()-function, missing QtGui and so on. Now we had a music player using the phonon framework which is not supported any…
Jan__
  • 216
  • 4
  • 9
2
votes
1 answer

custom QAbstractNetworkCache implementation; QAbstractNetworkCache::insert(QIODevice *device) device has no data

I am attempting to build my own custom QAbstractNetworkCache implementation for use with QNetworkAccessManager. I am having trouble with QAbstractNetworkCache::insert(QIODevice *device); inside this method, the device always arrives with 0 bytes to…
krdx
  • 1,315
  • 15
  • 22
2
votes
1 answer

Read text lines using QDataStream or QTextStream or neither from tcpsocket?

I am creating a simple TCP server, and have a slot/function built which reads incoming text from a client (telnet connection) on a TCP socket. I've used the Fortune code examples to help me, but had to remove QDataStream since it didn't work as…
TSG
  • 4,242
  • 9
  • 61
  • 121
2
votes
1 answer

What does "file.open(QIODevice::ReadOnly)" mean?

I am new to Qt, and I was learning on its Getting Started Page. I want to know what does the following statements mean and why are they required? In Open function: if (!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(this, tr("Error"),…
Vijay
  • 77
  • 1
  • 10
1
2 3 4