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.
    void CListsItmes::setAttr(int row, int col, QVariant value)
    if (!value.isValid())
    int i = listItem->value(row).remove(lsNameAttr.value(col)); //try remove before inserting
    listItem->value(row).insert(lsNameAttr.value(col), value);
    //work whis BD
    QUERY_COND cond;
    cond.nameAttr = "id";
    cond.sign = "=";
    cond.value = (*listItem).value(row).value(QString("id")).toString();
    datasoure.setItemAttr(cond, getName(), lsNameAttr.value(col), value);

  • 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 :-)

  • 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.

  • Congrats - and enjoy coding with Qt :-)

Log in to reply