PDA

View Full Version : QMap corruption



^NyAw^
6th March 2013, 13:23
Hi,

I have a problem with this piece of code:



QMap<quint32,quint32> qMap;
qMap[0] = 1;
qMap[1] = 1;
qMap[2] = 1;
qMap[3] = 0;
qMap[4] = 0;
QFont qFontBold = ui.treeWidget->headerItem()->font(0);
qFontBold.setBold(true);
QStringList qText;
qText << "Hello";
QTreeWidgetItem *pqItem = new QTreeWidgetItem(ui.treeWidget,qText);
pqItem->setFont(1,qFontBold); //This line changes qMap[0] to 0

//Here, if I check the value of qMap[0] it contains 0 instead of 1
quint32 qValue = qMap.value(0);


Using the debugger I can see that when setting the font to the item in the treeWidget, the qMap changes the value on key 0.

Could anyone try this code if you get the same error. Or maybe I'm doing something wrong?

Using Qt 4.8.1, Visual Studio 2008 and Windows XP.

Thanks,

Lesiok
6th March 2013, 14:59
Where and how qMap is defined ?

^NyAw^
6th March 2013, 16:40
Hi,

Sorry, I have changed the variable name when posting this. Read the code now

Added after 48 minutes:

Hi,

Finally found what happens.
I have connected the signal "itemChanged(QTreeWidgetItem*,int)" of QTreeWidget to a slot where it cheks if the item is cheked or not. As when setting the font the item changes, I modify the data of the QMap incorrectly as the item is not checked but I still not set the checkBox to true.
I will disable the signals from the QTreeWidget until it is filled.

Thanks,