Qt-interest Archive, April 2007
Serialising a QFile
Message 1 in thread
Hello List,
I want to send a file from a server app to a client app. Ideally, I'd
like to be able to serialize and unserialise an open QFile over a
QDataStream. However, I've run intoa few problems:
First, At the moment I'm using:
int writeRawData ( const char * s, int len )
to write data to the data stream and:
int readRawData ( char * s, int len )
to read the data at the other end.
I'm getting the size of the file using QFile::size(), which returns a
qint64.
This puzzles me. Why does QDataStream use a *signed* int in the
writeRawData method? When would you ever want to write a negative number
of bytes?
Similarly, why does QFile::size() return a qint64? The class
documentation mentions that size() may be 0 (when reading 'special'
files, like those in /proc/), but when would one encounter a negative
filesize?
Finally, I'd like to be able to serialize and unserialise QFile objects
without having to use the read* and write* methods of QDataStream.
Something like this would be nice:
<code>
QFile myfile("somefile.txt")
myfile.open(QFile::ReadOnly);
QDataStream ds(&my_connected_socket);
ds << myfile;
myfile.close();
</code>
And similar at the other end. I guess there's a good reason why someone
else hasn't done this already - seems it'd be pretty useful to me; or am
I missing something here. Is there a better way to do this?
Cheers,
--
[ signature omitted ]
Message 2 in thread
Hi,
All (almost all?) sizes are int's in Qt, and they're negative in case of
errors. There are arguments against this, as there are arguments in
favor of this.
This has been discussed a number of times on this list. Some choice had
to be made. Now that it's done there's no real point discussing it
again, especially since the Qt 4 API cannot be modified.
--
[ signature omitted ]
Message 3 in thread
Whoops! Sorry if I raised an old issue.
>
> This has been discussed a number of times on this list. Some choice
had
> to be made. Now that it's done there's no real point discussing it
> again, especially since the Qt 4 API cannot be modified.
>
Cheers,
BEGIN:VCARD
BEGIN:VCARD
VERSION:2.1
N:Richards;Thomas
FN:Thomas Richards
EMAIL;PREF;INTERNET:thomas.richards@xxxxxxxxx
REV:20070226T164514Z
END:VCARD
Message 4 in thread
Hi,
> Whoops! Sorry if I raised an old issue.
Oh, that's not a problem. The real problem is that I have already
forgotten the arguments for and against int's and I'm therefore unable
to provide a more precise answer :-/ I think there are discussions in
the archive dating back to Qt 1 or Qt 2, as well as more recent ones
(2007 or at least 2006).
--
[ signature omitted ]
Message 5 in thread
Heh,
>
> The real problem is that I have already
> forgotten the arguments for and against int's and I'm therefore unable
> to provide a more precise answer :-/ I think there are discussions in
> the archive dating back to Qt 1 or Qt 2, as well as more recent ones
> (2007 or at least 2006).
>
Not that I want to restart an old thread - but in my case, the fact that
QByteArray uses a uint32 for storing size is rather troublesome.. I want
to store an entire file in the array - some files may be larger than
4096 KB.
It also seems odd that QT defines types like 'qint32' which guarantee a
size of 32 bits, but these types seem not to be used in many areas of
the QT library where you'd want a guaranteed size. Or do the variable
types get 'un typedeffed' in the documentation?
Cheers,
--
[ signature omitted ]
BEGIN:VCARD
VERSION:2.1
N:Richards;Thomas
FN:Thomas Richards
EMAIL;PREF;INTERNET:thomas.richards@xxxxxxxxx
REV:20070226T164514Z
END:VCARD
Message 6 in thread
On 04.04.07 09:02:01, Thomas Richards wrote:
> Heh,
>
>
> >
> > The real problem is that I have already
> > forgotten the arguments for and against int's and I'm therefore unable
> > to provide a more precise answer :-/ I think there are discussions in
> > the archive dating back to Qt 1 or Qt 2, as well as more recent ones
> > (2007 or at least 2006).
> >
>
> Not that I want to restart an old thread - but in my case, the fact that
> QByteArray uses a uint32 for storing size is rather troublesome.. I want
> to store an entire file in the array - some files may be larger than
> 4096 KB.
Uhm with 32 bits you can have numbers up to about 4.2 billions, which
means 4GB. And I really doubt you can easily handle files that large in
memory (unless you have monster machines with 8 ot 16 GB).
Andreas
--
[ signature omitted ]
Message 7 in thread
>
> Uhm with 32 bits you can have numbers up to about 4.2 billions, which
> means 4GB. And I really doubt you can easily handle files that large
in
> memory (unless you have monster machines with 8 ot 16 GB).
>
Oops! So you can.. my mistake.
--
[ signature omitted ]
BEGIN:VCARD
VERSION:2.1
N:Richards;Thomas
FN:Thomas Richards
EMAIL;PREF;INTERNET:thomas.richards@xxxxxxxxx
REV:20070226T164514Z
END:VCARD
Message 8 in thread
Hi,
> It also seems odd that QT defines types like 'qint32' which guarantee a
> size of 32 bits, but these types seem not to be used in many areas of
> the QT library where you'd want a guaranteed size.
That's maybe because you don't really need a guaranteed size ;-) At
least not that bad...
--
[ signature omitted ]