[SOLVED] write QHash to a file



  • I wanna write a QHash to a file, so that the file has the structure

    value:key
    value1:key
    .
    .
    .

    but somethin is wrong with the line

    out << i.key <<.....

    @QHash<QString, QVariant> entries;
    entries.insert("key1", 1);
    entries.insert("key2", "seven");
    entries.insert("key3", 22.7);
    QFile fileOut("/fs1/PerlQt/QtCreator/test/variables.inp");
    if (fileOut.open(QFile::WriteOnly|QFile::Text)){
    QTextStream out(&fileOut);
    QHashIterator<QString, QVariant> i(entries);
    while (i.hasNext()) {
    i.next();
    out << i.key() << ": " << i.value() << endl;
    }
    //out << entries;
    fileOut.flush();
    fileOut.close();@


  • Lifetime Qt Champion

    Hi,

    What goes wrong ?

    Try with: i.value().toString()

    Hope it helps



  • Thanks that was the Problem....


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.