PDA

View Full Version : QList and QVariant crashes with VS2010



ZHawk
3rd January 2011, 12:03
Hi,

i have Qt 4.7.1 and VS2010 Express

the following code crashes with no reason:

#include "QApplication"
#include <QtCore>

void test( )
{
QVariant v, v2;
QList<QVariant> list;
v.setValue(1); // init variant with integer = 1
list.append(v); // add variant to list
v2.setValue(list); // add list to variant
qDebug() << v;
qDebug() << list;
qDebug() << v2;
// leaving this function will crash with a corrupted heap
// output see below
}

int main( int argc , char *argv[] )
{
test();
QApplication app(argc, argv);
return app.exec();
}

my output:

QVariant(int, 1)
(QVariant(int, 1) )
QVariant(QVariantList, (QVariant(int, 1) ) )

after the crash it points me to "qguivariant.cpp" line 280:

qcoreVariantHandler()->clear(d);

any help ?
thanks

Zlatomir
3rd January 2011, 12:32
Have you builded Qt framework with VS2010? Or you are using the already build with VS2008 downloaded from qt.nokia site?
If you didn't build Qt with VS2010 you should do it, else you can get errors at run-time (like corrupted heap) or if you already rebuild Qt with 2010 you should give a little more information about the error.

//i'm not at my system with VS right now, but i will test your code a little bit later

ZHawk
3rd January 2011, 13:04
i am using the build i downloaded from qt.nokia download section
i have not tried to compile qt with vs2010 because i assumed that 4.7.x should work with it

the only info i have is this small test code.
i require this data structure as some Qt functions do return such a structure (COM objects)

Zlatomir
3rd January 2011, 13:16
The dlls are not compatible, you should build Qt with VS2010
As another example see this topic (http://www.qtcentre.org/threads/35734-QT-Console-application-QTextStream?highlight=vs+2010) too.
Some applications work with dlls builded with Vs2008, but some give strange errors at run-time, and then you need to build Qt with the same compiler version as application using it's dlls.

//i tested your function with VS2010 and Qt (built with VS2010) and it doesn't crash

ZHawk
3rd January 2011, 13:33
thank you for your help