[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:
    [code] QList<QVariant> list;
    list.append(1);
    list.append(2.0f);
    list.append(3.0);

    list.append(4);
    list.append(5);
    list.append(6);
    

    [/code]

    On the Sender side, the VS2008 Debug Stack of this QList<QVariant> looks like this:
    [code]

    • list [6](int = 1,type = 135,double = 3.0000000000000000,int = 4,int = 5,int = 6) QList<QVariant>

    • [0] int = 1 QVariant

      [0] 1 int

    • [1] type = 135 QVariant

    • [0] 0x00000000 <Schlechtes Ptr> char *

    CXX0030: Fehler: Ausdruck kann nicht ausgewertet werden

     [1] 135 unsigned int
    
    • [2] double = 3.0000000000000000 QVariant

      [0] 3.0000000000000000 double

    • [3] int = 4 QVariant

      [0] 4 int

    • [4] int = 5 QVariant

      [0] 5 int

    • [5] int = 6 QVariant

      [0] 6 int

    [/code]

    Translation:
    [quote]Schlechtes Ptr = Bad Pointer
    Fehler: Ausdruck kann nicht ausgewertet werden = Error: Expression can not be evaluated[/quote]

    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:
    [code]

    • list [3](int = 1,type = 135,type = 0) QList<QVariant>

    • [0] int = 1 QVariant

      [0] 1 int

    • [1] type = 135 QVariant

    • [0] 0x00000000 <Schlechtes Ptr> char *

    CXX0030: Fehler: Ausdruck kann nicht ausgewertet werden

     [1] 135 unsigned int
    
    • [2] type = 0 QVariant

    • [0] 0x00000000 <Schlechtes Ptr> char *

    CXX0030: Fehler: Ausdruck kann nicht ausgewertet werden

     [1] 0 unsigned int
    

    [/code]

    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:
    [code]configure -debug-and-release -opensource -vcproj -qmake -qt-sql-sqlite -platform win32-msvc2008 -mp -system-zlib -system-libpng -no-libjpeg[/code]

    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
    [code]bool QVariant::canConvert(Type t) const
    {
    //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
    ...
    }
    [/code]

    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?



  • [quote author="FloGe" date="1335995003"]
    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.
    [/quote]
    As far as I know, QVariant's behavior for float changed from Qt 4.6.0.

    [quote author="FloGe" date="1335995003"]
    On the Sender side, the VS2008 Debug Stack of this QList<QVariant> looks like this:
    [/quote]

    If you are using QtCreator or Qt addon for MSVC, I think this should be a bug of QtCreator or Qt addon for MSVC.

    [quote author="FloGe" date="1335995003"]
    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.
    [/quote]

    Can you tell us how do you transfer it?



  • [quote author="1+1=2" date="1335997135"]Can you tell us how do you transfer it?[/quote]
    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
    [code]out.setVersion( out.version() );[/code]

    in the client while I had not updated the
    [code]in.setVersion(QDataStream::Qt_4_2);[/code]

    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.

    [quote author="1+1=2" date="1335997135"]If you are using QtCreator or Qt addon for MSVC, I think this should be a bug of QtCreator or Qt addon for MSVC.[/quote]
    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:
    [quote author="Andre" date="1308739392"]Note that in Qt 5, the distinction between QVariant::Type and QMetaType::Type will most likely go away.[/quote]

    Thanks again for your help, especially this quickly!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.