Hi
I'm using Qt 4.3.3 and trying to stream binary data (read from an arbitrary file). Therefore I started with an example as found in the Qt documentation just a few lines of code:
	
	- #include <QVariant> 
- #include <QDataStream> 
- #include <QString> 
- #include <QStringList> 
- #include <QFile> 
-   
-   
- int main(int argc, char *argv[]) 
- { 
-   
-     QVariant-  v (123)- ;                               // The variant now contains
 
-     int x = v.toInt();                              // x = 123 
-   
-     qDebug("x=%#x", x);                      // prints x 
-   
-   
-                                                           // prints "Type is int" 
-     qDebug("Type is %s, userType=%d", v.typeName(), v.userType()); 
-   
-     in >> v;                                         // *Should* reads an Int variant 
-   
-     int z = v.toInt();                              // z = 0 !!!! 
-                                                          // Type is no longer Int variant: 
-     qDebug("Type is %s, userType=%d", v.typeName(), v.userType()); 
-   
-     int n; 
-     in >> n;                                         // Reads a normal int 
-   
-     qDebug("n=%#x", n);                      // this just works  
-   
-     return 1; 
- } 
        #include <QVariant>
#include <QDataStream>
#include <QString>
#include <QStringList>
#include <QFile>
int main(int argc, char *argv[])
{
    QFile file("./test");
    file.open(QIODevice::ReadOnly);
    QVariant v(123);                              // The variant now contains
    int x = v.toInt();                              // x = 123
    qDebug("x=%#x", x);                      // prints x
    QDataStream in(&file);                      
                                                          // prints "Type is int"
    qDebug("Type is %s, userType=%d", v.typeName(), v.userType());
    in >> v;                                         // *Should* reads an Int variant
    int z = v.toInt();                              // z = 0 !!!!
                                                         // Type is no longer Int variant:
    qDebug("Type is %s, userType=%d", v.typeName(), v.userType());
    int n;
    in >> n;                                         // Reads a normal int
    qDebug("n=%#x", n);                      // this just works 
    return 1;
}
To copy to clipboard, switch view to plain text mode 
  
Here the few lines produce the following output:
markus@athlon:~/Test/bin> ./test
x=0x7b
Type is int, userType=2
QVariant::load: unable to load type 1061506118.
Type is (null), userType=1061506118
n=0x1010000
markus@athlon:~/Test/bin>
So it looks like the QVariant type is lost somehow during the call to the operator>>.  Does anybody have an idea why the type has suddenly the value 1061506118 instead of 2?
Best regards, Markus
				
			
Bookmarks