Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, March 2002
QVariant, long longs


Message 1 in thread

How come the QVariant does not have a toLongLong() method?  Why can't we 
store long longs (64 bit ints) in a QVariant?  Does this not mean I'll have 
problems pulling back a 64-bit int using Qt's SQL classes?


Message 2 in thread

On Wed, Mar 13, 2002 at 02:54:37PM -0700, Christopher Thompson wrote:
> How come the QVariant does not have a toLongLong() method?  Why can't we 
> store long longs (64 bit ints) in a QVariant?  Does this not mean I'll have 
> problems pulling back a 64-bit int using Qt's SQL classes?

Simple because 'long long' isn't guaranteed to be 64 bit on all 
Qt supported platforms.


Simon


Message 3 in thread

On Wednesday 13 March 2002 3:00 pm, Simon Hausmann wrote:
>
> Simple because 'long long' isn't guaranteed to be 64 bit on all
> Qt supported platforms.

Fair enough.

However, we have toInt() but no toLong() and no toLongLong() methods.  In 
other words, we can pull out of a QVariant whatever will fit in an int in our 
architecture.  There's no way to pull out larger numbers, at least as far as 
I can see.  This seems to me to be a significant limitation but I could just 
be missing something.


Message 4 in thread

On Wednesday 13 March 2002 15:00, Simon Hausmann wrote:
> On Wed, Mar 13, 2002 at 02:54:37PM -0700, Christopher Thompson wrote:
> > How come the QVariant does not have a toLongLong() method?  Why can't we
> > store long longs (64 bit ints) in a QVariant?  Does this not mean I'll
> > have problems pulling back a 64-bit int using Qt's SQL classes?
>
> Simple because 'long long' isn't guaranteed to be 64 bit on all
> Qt supported platforms.

Not sure why thats an argument not to have long long supported.  I would like 
to see QVariant have toInt(), toLong(), and toLongLong() and it doesn't 
really matter how many bits each supports.

-- 
 [ signature omitted ] 

Message 5 in thread

long long isn't even a standard C++ type...

However, C99 guarantees long long is at least 64 bits.  I assume this
carries forward into the next C++ standard in some form.

-- Paul.

> -----Original Message-----
> From: Simon Hausmann [mailto:hausmann@kde.org] 
> Sent: 13 March 2002 22:01
> To: Christopher Thompson
> Cc: qt-interest@trolltech.com
> Subject: Re: QVariant, long longs
> 
> 
> On Wed, Mar 13, 2002 at 02:54:37PM -0700, Christopher Thompson wrote:
> > How come the QVariant does not have a toLongLong() method?  
> Why can't 
> > we
> > store long longs (64 bit ints) in a QVariant?  Does this 
> not mean I'll have 
> > problems pulling back a 64-bit int using Qt's SQL classes?
> 
> Simple because 'long long' isn't guaranteed to be 64 bit on all 
> Qt supported platforms.
> 
> 
> Simon
> 
> --
> List archive and information: http://qt-interest.trolltech.com
> 


Message 6 in thread

Not all C++ compilers will support the common "long long" extension.
VC++, for instance, does not support this idiopm but provides the
__int64 type.

The minimum a C/C++ compiler is guaranteed to provide int-wise is a
16-bit int, yet Qt will most likely fail on compilers that provide 16
bit ints.  Long is required to be at least 32 bits.  C99 defines that
long long is at least 64 bits.

Some compilers I've used define sizeof(char) == sizeof(int) ==
sizeof(long) == sizeof(floar).

-- Paul.

> -----Original Message-----
> From: Brad Pepers [mailto:brad@linuxcanada.com] 
> Sent: 13 March 2002 22:13
> To: hausmann@kde.org
> Cc: qt-interest@trolltech.com
> Subject: Re: QVariant, long longs
> 
> 
> On Wednesday 13 March 2002 15:00, Simon Hausmann wrote:
> > On Wed, Mar 13, 2002 at 02:54:37PM -0700, Christopher 
> Thompson wrote:
> > > How come the QVariant does not have a toLongLong() method?  Why 
> > > can't we store long longs (64 bit ints) in a QVariant?  Does this 
> > > not mean I'll have problems pulling back a 64-bit int 
> using Qt's SQL 
> > > classes?
> >
> > Simple because 'long long' isn't guaranteed to be 64 bit on all Qt 
> > supported platforms.
> 
> Not sure why thats an argument not to have long long 
> supported.  I would like 
> to see QVariant have toInt(), toLong(), and toLongLong() and 
> it doesn't 
> really matter how many bits each supports.
> 
> -- 
> Brad Pepers
> brad@linuxcanada.com
> 
> --
> List archive and information: http://qt-interest.trolltech.com
> 


Message 7 in thread

On Wednesday 13 March 2002 3:52 pm, Paul Curtis wrote:
> Not all C++ compilers will support the common "long long" extension.
> VC++, for instance, does not support this idiopm but provides the
> __int64 type.

True enough.  Nevertheless, QVariant should support 64 bit numbers because it 
is used by the Qt SQL classes.

> Some compilers I've used define sizeof(char) == sizeof(int) ==
> sizeof(long) == sizeof(floar).

sizeof(char) is, by definition, 1.  This is on p.75 of The C++ Programming 
Language, Special Edition, by Stroustrup.  Of course, if the ISO standard 
actually says otherwise, that has priority.  :)

If a compiler defined sizeof(int) == sizeof(long) == sizeof(float) == 1 and 
assuming bytes were 8 bits, that doesn't leave much room to maneuver.  :)


Message 8 in thread

Why do you not store things as a double as QVariant can hold that?

That means you get a straight 56-bit integer on all platforms.  Ok, not
quite 64 bits, but well past 32 bits.

-- Paul.

> -----Original Message-----
> From: Christopher Thompson [mailto:christ@axionspatial.com] 
> Sent: 13 March 2002 22:04
> To: hausmann@kde.org
> Cc: qt-interest@trolltech.com
> Subject: Re: QVariant, long longs
> 
> 
> On Wednesday 13 March 2002 3:00 pm, Simon Hausmann wrote:
> >
> > Simple because 'long long' isn't guaranteed to be 64 bit on all Qt 
> > supported platforms.
> 
> Fair enough.
> 
> However, we have toInt() but no toLong() and no toLongLong() 
> methods.  In 
> other words, we can pull out of a QVariant whatever will fit 
> in an int in our 
> architecture.  There's no way to pull out larger numbers, at 
> least as far as 
> I can see.  This seems to me to be a significant limitation 
> but I could just 
> be missing something.
> 
> --
> List archive and information: http://qt-interest.trolltech.com
> 


Message 9 in thread

On Wednesday 13 March 2002 3:53 pm, Paul Curtis wrote:
> Why do you not store things as a double as QVariant can hold that?
>
> That means you get a straight 56-bit integer on all platforms.  Ok, not
> quite 64 bits, but well past 32 bits.

Well, I want 64 bits of precision.  That's what is stored in the database, 
that's what is retrieved into a QVariant, that's what I want.

That said, I am mostly being pedantic.  Due to other limitations, 32 bits is 
actually sufficient for my app.  I still think QVariant should support long 
and long long, though.


Message 10 in thread

On Wednesday 13 March 2002 15:53, Paul Curtis wrote:
> Why do you not store things as a double as QVariant can hold that?
>
> That means you get a straight 56-bit integer on all platforms.  Ok, not
> quite 64 bits, but well past 32 bits.

The databases I use (Firebird and Sybase ASA) both support 64 bit integers 
using numeric(18,0) (or I can use BIGINT on Sybase as well).  But if QVariant 
doesn't support this, I can't use it as easily.  I have a case where I store 
unique ids and use the top 2 digits for a store number and the bottom 16 for 
the transaction number but thats not going to work with Qt.

Of course I can always get the value as a string and then internally convert 
it to a long long but its more of a pain.

-- 
 [ signature omitted ] 

Message 11 in thread

> On Wednesday 13 March 2002 3:52 pm, Paul Curtis wrote:
> > Not all C++ compilers will support the common "long long" extension.
> > VC++, for instance, does not support this idiopm but provides the
> > __int64 type.
> 
> True enough.  Nevertheless, QVariant should support 64 bit 
> numbers because it 
> is used by the Qt SQL classes.
> 
> > Some compilers I've used define sizeof(char) == sizeof(int) ==
> > sizeof(long) == sizeof(floar).
> 
> sizeof(char) is, by definition, 1.  This is on p.75 of The 
> C++ Programming 
> Language, Special Edition, by Stroustrup.  Of course, if the 
> ISO standard 
> actually says otherwise, that has priority.  :)
> 
> If a compiler defined sizeof(int) == sizeof(long) == 
> sizeof(float) == 1 and 
> assuming bytes were 8 bits, that doesn't leave much room to 
> maneuver.  :)

The compile in question is the TI compiler for the C40 which is a
word-addressed machine.  In this case, each character is four bytes.
You rightly point out that sizeof(char)==1 as defined by ISO, and the TI
compiler indeed defines sizeof(char)==1.  The TI C compiler fulfils all
that is required of it by the ISO standard.  The fact that
sizeof(long)==1 is incedental.

-- Paul.


Message 12 in thread

I think a toLong() that is guaranteed to return 32-bits is essential for the SQL stuff.  Maybe there is something I am missing, as well.

>>> Brad Pepers <brad@linuxcanada.com> 03/13/02 02:12PM >>>
On Wednesday 13 March 2002 15:00, Simon Hausmann wrote:
> On Wed, Mar 13, 2002 at 02:54:37PM -0700, Christopher Thompson wrote:
> > How come the QVariant does not have a toLongLong() method?  Why can't we
> > store long longs (64 bit ints) in a QVariant?  Does this not mean I'll
> > have problems pulling back a 64-bit int using Qt's SQL classes?
>
> Simple because 'long long' isn't guaranteed to be 64 bit on all
> Qt supported platforms.

Not sure why thats an argument not to have long long supported.  I would like 
to see QVariant have toInt(), toLong(), and toLongLong() and it doesn't 
really matter how many bits each supports.

-- 
 [ signature omitted ] 

Message 13 in thread

>it doesn't really matter how many bits each supports.

I think how many bits each supports is the entire issue.
If not, then just use toInt() or toUInt() and cast it to long or unsigned long.  Since sizeof(int) and sizeof(long) both return 4 on both Linux and Windows I guess I don't care.  That is what *I* was missing.  LONGLONG is 64 bits, and if you don't have a platform that supports a simple data type that wide, how would you use it?


Message 14 in thread

On Thursday 14 March 2002 10:29, James Hamilton wrote:
> >it doesn't really matter how many bits each supports.
>
> I think how many bits each supports is the entire issue.

Trying to enforce the number of bits is not a good idea.  You say that 
sizeof(long) returns 4 on Windows and Linux but that is true only on some 
platforms.  On some Linux platforms (Alpha? PowerPC? Itanium?) the long is 
really 64 bits and long long is 128!

> If not, then just use toInt() or toUInt() and cast it to long or unsigned
> long.

This doesn't help is sizeof(int) is 4 and sizeof(long) is 8 since it can't 
add the extra info.

> Since sizeof(int) and sizeof(long) both return 4 on both Linux and
> Windows I guess I don't care.

You have to care if you ever plan to port to a differet arch.

> That is what *I* was missing.  LONGLONG is
> 64 bits, and if you don't have a platform that supports a simple data type
> that wide, how would you use it?

All I wanted was the ability to use the full range of built-in data types in 
QVariant which means int, long, and long long.  Of course some compilers 
don't support long long (is which case it would be fine to not define the 
toLongLong() method) or else have a different name for it (in which case it 
would be nice to have a define like exists now for BOOL).

-- 
 [ signature omitted ]