September 13, 2011

kunashir kunashir
Lab Rat
41 posts

QMap/QHash: not remove and not reinsert item.

 

Hello!
I have completed QMap/QHash.
And I try remove or reinsert value whis a key, , which is already in Map.
But nothing happens.
If I try remove, function return value not equal 0, but in the debugger value remains the same.

  1. void CListsItmes::setAttr(int row, int col, QVariant value)
  2. {
  3.     if (!value.isValid())
  4.         return;
  5.     int i = listItem->value(row).remove(lsNameAttr.value(col)); //try remove before inserting
  6.     listItem->value(row).insert(lsNameAttr.value(col), value);
  7.     //work whis BD
  8.     QUERY_COND cond;
  9.     cond.nameAttr = "id";
  10.     cond.sign         = "=";
  11.     cond.value = (*listItem).value(row).value(QString("id")).toString();
  12.     datasoure.setItemAttr(cond, getName(), lsNameAttr.value(col), value);
  13. }

3 replies

September 13, 2011

Volker Volker
Ant Farmer
5428 posts

And what is your problem? From that dump of variable names, we cannot get anything meaningful (we do not know your code).

The best way to present those problems to a forum is to create a test case that demonstrates the erroneous behavior. This usually consists a small, complete, compilable program; most often less more than a main function and one or two small classes. And chances are good that you stumble over the cause of the problem during the process of preparing that test case :-)

September 13, 2011

kunashir kunashir
Lab Rat
41 posts

Thank you!

Your method realy work – I began to implement my problem, and understand that – function value of QList return const T.
Change “value” to [] and all is ok.

September 13, 2011

Volker Volker
Ant Farmer
5428 posts

Congrats – and enjoy coding with Qt :-)

 
  ‹‹ Invalid glyphset parameter      Transparent scroll bar in QListView ››

You must log in to post a reply. Not a member yet? Register here!