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

Thiago Macieira thiago.macieira at intel.com
Mon Apr 21 04:56:54 CEST 2014


Em dom 20 abr 2014, às 22:13:47, Denis Shienkov escreveu:
> == Second issue ==
> 
> What about two scenarios ? (e.g. for some abstract I/O device):
> 
> 1) Without flush():
> 
> MyClass::foo()
> {
> dev.write('a');
> dev.write('b');
> }
> 
> MyClass::bar()
> {
> dev.write('c');
> dev.write('d');
> }
> 
> when, the bar() method were called after the foo(), when the Qt-event
> loop was entered after foo().
> i.e. for example both foo() and bar() are the buttons-clicked-handlers.
> 
> then I expected to receive two: bytesWritten(2 byte) + bytesWritten(2
> byte) signals

That might not happen. It depends on whether the underlying device was 
writeable in the meantime and that the socket notifier did fire.

> 2) With flush():
> 
> MyClass::foo()
> {
> dev.write('a');
> dev.write('b');
> }
> 
> MyClass::bar()
> {
> dev.write('c');
> dev.write('d');
> dev.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").
> i.e. for example both foo() and bar() are the buttons-clicked-handlers,
> but the bar-button-clicked in the moment when not all data was written
> from the previous foo-button-clicked.
> 
> then I expected to receive one bytesWritten(4 byte) signal

flush() does not guarantee that any data gets written. It s equivalent to 
waitForBytesWritten(0), which will not write anything if the device is not 
writeable. And it won't block waiting for it to become writeable.

> 3) With double flush():
> 
> MyClass::foo()
> {
> dev.write('a');
> dev.write('b');
> dev.flush();
> }
> 
> MyClass::bar()
> {
> dev.write('c');
> dev.write('d');
> dev.flush();
> }
> 
> what here I expect to receive after all data will be really transferred?
> 
> to receive two: bytesWritten(2 byte) + bytesWritten(2 byte) signals, or
> to receive one bytesWritten(4 byte) signal ?

Either is fine. See above: flush() does not guarantee that data gets written, 
since it won't block.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list