[Development] [QIODevice]How to correctly treat/understand of the documentation?

Denis Shienkov denis.shienkov at gmail.com
Thu Apr 17 16:13:39 CEST 2014


Hi all.

I have the question concerning correct treatment of documentation and
implementation of I/O methods, e.g. for QtSerialPort.

== write ==

For example, regarding to the QIODevice::write() method. Investigating of
Qt5 source codes I see two approaches in classes derived from QIODevice (I
talk about the buffered mode):

1) "Deferred writing"

When QIODevice::write () only adds a next portion of data to the internal
write buffer. But real data transmission is carried out later, on an next
step: on a signal from an notifier (for example from the Tx FIFO event,
that signalise about FIFO is empty and can be sent next portion of data
from the internal buffer).

This behavior is implemented, for example in the QAbstractSocket for a
buffered mode.

2) "Directly writing"

This approach when the QIODevice::write() transfers data at once to the
device, directly.

I.e. in my head there is a confusion. How it is necessary to do for the
buffered mode more correctly?
For me, more pleasant that is the first method...

But, if I am not right (i.e. when need to use "directly" writing to
minimize time between packets), then what reasons in TCP socket the first
"deferred" method is used?

== flush ==

What expected behavior for the QIODevice::flush() method and for the
bytesWritten(qint64) signal?

For example two scenarios:

1) Without flush()

MyClass::foo()
{
    p.write('a');
    p.write('b');
}

MyClass::bar()
{
    p.write('c');
    p.write('d');
}

when, the bar() method were called after foo() (with some delay), but when
not all data ("a" and "b") was written (e.g. was in time written only "a").

then I expected to receive two: bytesWrittenSignal(2 byte) +
bytesWrittenSignal(2 byte)


2) With flush()

MyClass::foo()
{
    p.write('a');
    p.write('b');
}

MyClass::bar()
{
    p.write('c');
    p.write('d');
    p.flush();
}

when, the bar() method were called after foo() (with some delay), but when
not all data ("a" and "b") was written (e.g. was in time written only "a").

then I expected to receive one bytesWrittenSignal(4 byte)

Whether correctly I understandаnd for expected behavior?


Best regards,
Denis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140417/73bf7252/attachment.html>


More information about the Development mailing list