Qt World Summit: Register Today!

Cannot delete key from QSettings on iOS

  • Hello,

    I am using Qt 5.1 compiled to run on iOS devices and I am using QSettings to save some info that I need my app to log.

    I am saving strings under keys of the following type:

    At some point I need to be able to get rid of these strings from QSettings. To do so I do the following:

    QStringList logKeys = mSettings.allKeys();
    qDebug() << "log (start-end)" << startTime << "-" << endTime;
    for(int i = 0; i < logKeys.size(); i++) {
    QDateTime time = QDateTime::fromString(logKeys[i].split("/")[0], "yyyy-MM-ddTHH:mm:ss:zzz");
    if(time >= start && time <= end) {
    qDebug() << "Delete " << (LOG_TAG + "/" + logKeys[i]);
    mSettings.remove(LOG_TAG + "/" + logKeys[i]);

    Here @LOG_TAG = "log"@

    When that code runs here's what it prints out on the terminal:

    @log (start-end) "2013-08-01T14:42:54:267" - "2013-08-01T14:44:40:999"
    Delete "log/2013-08-01T14:42:54:267/ACCESSED"
    Delete "log/2013-08-01T14:42:56:120/ACCESSED"
    Delete "log/2013-08-01T14:42:57:826/ACCESSED"
    Delete "log/2013-08-01T14:44:40:999/DEVICE"@

    Immediately after, If I try and print out all the items with keys starting with LOG_TAG it outputs:

    @LOG: QMap(("2013-08-01T14:42:54:267/ACCESSED", "INFO:UserMenu")("2013-08-01T14:42:56:120/ACCESSED", "INFO:SignInMenu")("2013-08-01T14:42:57:826/ACCESSED", "INFO:WorldRanks"))@

    As you can see it successfully deleted

    but not the other keys.

    Any idea why this might be happening?



  • Lifetime Qt Champion


    Since you're using QSettings in an unusual way, did you call sync() to send the changes to permanent storage ?

    Hope it helps

Log in to reply