[SOLVED] QVariant: float, type = 135 broken in 4.8.0 ?
I have an application that places several int and float values inside a QList<QVariant> and then transfers them via QTcpSocket to a Server, the rest of the code is very close to the Fortune Client/Server Example.
This used to work fine with Qt up to 4.7.4 as far as I know, I noticed that it stopped working properly when trying to use it with Qt 4.8.0 but it might have happened earlier in 4.6.x or 4.7.x.
I tried some reduced code to test the “new” QVariant:
- list.append(1);
- list.append(2.0f);
- list.append(3.0);
- list.append(4);
- list.append(5);
- list.append(6);
On the Sender side, the VS2008 Debug Stack of this QList<QVariant> looks like this:
- [0] 1 int
- - [0] 0x00000000 <Schlechtes Ptr> char *
- CXX0030: Fehler: Ausdruck kann nicht ausgewertet werden
- [1] 135 unsigned int
- [0] 3.0000000000000000 double
- [0] 4 int
- [0] 5 int
- [0] 6 int
Translation:
Schlechtes Ptr = Bad Pointer
Fehler: Ausdruck kann nicht ausgewertet werden = Error: Expression can not be evaluated
So something seems to go wrong here already. Ints are fine, Doubles are fine, Floats aren’t.
On the Sender side, this QList<QVariant> arrives:
- [0] 1 int
- - [0] 0x00000000 <Schlechtes Ptr> char *
- CXX0030: Fehler: Ausdruck kann nicht ausgewertet werden
- [1] 135 unsigned int
- - [0] 0x00000000 <Schlechtes Ptr> char *
- CXX0030: Fehler: Ausdruck kann nicht ausgewertet werden
- [1] 0 unsigned int
So apparently everything after the broken float QVariant doesn’t get transmitted properly anymore, which is not surprising if there is already a problem setting up the QVariant correctly before it has been sent.
I am using Qt 4.8.0 which has been compiled with the following configuration:
- configure -debug-and-release -opensource -vcproj -qmake -qt-sql-sqlite -platform win32-msvc2008 -mp -system-zlib -system-libpng -no-libjpeg
I found this but don’t fully understand what it means, or why this has not been addressed:
http://svn.netlabs.org/repos/qt4/trunk/src/corelib/kernel/qvariant.cpp
- {
- //we can treat floats as double
- //the reason for not doing it the "proper" way is that QMetaType::Float's value is 135,
- //which can't be handled by qCanConvertMatrix
- //In addition QVariant::Type doesn't have a Float value, so we're using QMetaType::Float
- ...
- }
Is anyone able to reproduce this Bug?
Is this a known Bug?
Does anyone know whether it was introduced with 4.8.0 or earlier?
Has it been fixed in 4.8.1 or is it already on the list of fixes for the next release?
2 replies
This used to work fine with Qt up to 4.7.4 as far as I know, I noticed that it stopped working properly when trying to use it with Qt 4.8.0 but it might have happened earlier in 4.6.x or 4.7.x.
As far as I know, QVariant’s behavior for float changed from Qt 4.6.0.
On the Sender side, the VS2008 Debug Stack of this QList<QVariant> looks like this:
If you are using QtCreator or Qt addon for MSVC, I think this should be a bug of QtCreator or Qt addon for MSVC.
So apparently everything after the broken float QVariant doesn’t get transmitted properly anymore, which is not surprising if there is already a problem setting up the QVariant correctly before it has been sent.
Can you tell us how do you transfer it?
Can you tell us how do you transfer it?
My sendMessage Function is the one from the Fortune Client/Server Example, and looking at them again, I found the issue: I recently went to use
- out.setVersion( out.version() );
in the client while I had not updated the
in the server, changing the in.setVersion and out.setVersion calls to be consistent everywhere fixed the issue. Thank you for pointing me in the right direction, and sorry for making this look bigger than it is.
If you are using QtCreator or Qt addon for MSVC, I think this should be a bug of QtCreator or Qt addon for MSVC.I am using the Qt Visual Studio Addin 1.1.10 in Visual Studio 2008 (without SP1). Yes, there might be an issue with the Debug Stack display, and it might have to do with the fact that ints are handled as QVariant::Int, doubles are handled as QVariant::Double, but floats are handled as QMetaType::Float. And this might be fixed in Qt 5:
Note that in Qt 5, the distinction between QVariant::Type and QMetaType::Type will most likely go away.
Thanks again for your help, especially this quickly!
You must log in to post a reply. Not a member yet? Register here!


