Am Sun, 13 May 2018 23:50:20 -0700 schrieb Thiago Macieira <thiago.macie...@intel.com>:
> On Sunday, 13 May 2018 23:28:47 PDT alexander golks wrote: > > > In fact, QDataStream can't recover from any errors. > > > > as you've said, my origin problem is no error. > > wouldn't it be possible for QDataStream to handle this no-errors, too? > > It already does. > > int QDataStream::writeRawData(const char *s, int len) > { > CHECK_STREAM_WRITE_PRECOND(-1) > int ret = dev->write(s, len); > if (ret != len) > q_status = WriteFailed; > return ret; > } it does, partly. the write has not failed, it simply has not written all data. > > otherwise, as i still don't know the "no-error" conditions, i would always > > need to use something like QDataStream::writeRawData, which is barely more > > then a QFile::write, and no other operator<< methods. > > it will tell you if there was a write failure. See above. yes, but all other operator<< methods not. what about something like: int QDataStream::writeRawData(const char *s, int len) { CHECK_STREAM_WRITE_PRECOND(-1) qint64 bytesToWrite = len; qint64 totalWritten = 0; do { int ret = dev->write(s + totalWritten, bytesToWrite); if(ret < 0) break; totalWritten += ret; bytesToWrite -= ret; } while (totalWritten < len); if(totalWritten != len) q_status = WriteFailed; return totalWritten; } and appropriate modifications for all other related methods. -- /* * All generalizations are false, including this one. * -- Mark Twain */ _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest