[Development] QFile: writing via a temporary file
Thiago Macieira
thiago.macieira at intel.com
Fri Jan 6 22:09:26 CET 2012
On Friday, 6 de January de 2012 21.38.19, David Faure wrote:
> > The first solution doesn't look nice. It would have to fail opening
> > completely.
>
> Well, this is just like using ReadOnly | Truncate, for instance. These are
> incompatible. What happens? Truncate will be ignored, and you don't even get
> a warning. (Both the code and a quick test indicate this).
I'd have expected that to give you a read-only 0-bytes file. In any case, both
flags are specified at the same time. If we're going to go with this feature in
QFile, then the flag should be specified in the call to open().
> > But I think I prefer a QSaveFile, derived from QFile, with the proper
> > semantics.
>
> Heh, a 4th solution, to make this debate even more endless :-)
Fourth? I thought it was your first. I considered "separate class from QFile"
and "QFile" as the two options.
> Why would this be better? It can't be "because it's not clear which file
> some methods should work on" (Joao's argument), since it would still have
> all the QFile methods. It can't be because we need additional API compared
> to QFile, or is it, for one single rollback method? ;)
QTemporaryFile derives from QFile. I think a QSaveFile is the same as a
QTemporaryFile, except it's not temporary: when you close it, instead of it
going "poof!", it gets made permanent.
The code that does the writing doesn't need to know that it's operating on a
regular QFile, a QTemporaryFile or a QSaveFile.
> It could even add an unnecessary need for casting, I could imagine: a public
> method takes a QFile, then you realize it should handle disk-full
> situations better, so you pass it a QSaveFile and you have to downcast it
> internally to call rollback in case of a truncated write...). This doesn't
> sound appealing. A QFile builtin feature makes this much nicer.
What?
If the method accepted a QFile pointer before, then a class derived from QFile
will automatically downcast to the type.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Intel Sweden AB - Registration Number: 556189-6027
Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120106/dd62b03e/attachment.sig>
More information about the Development
mailing list