Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSettings::beginWriteArray() | Is this output normal and expected ?
Forum Updated to NodeBB v4.3 + New Features

QSettings::beginWriteArray() | Is this output normal and expected ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 491 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    grpace
    wrote on last edited by
    #1

    Hello, folks. Qt newbie here.

    I'm using QSettings in combination with a QTableWidget to save some user configurations. At this point, my code appears to be saving the data from the table, but I'm not clear on why it's saving the data in the manner that it is, and it's very likely the way I have it coded.

    You should be able to see the table here.

    Here is the code I'm using (don't like the way this forum software handles code pasting):

    userConfigs.beginGroup("ComponentAliases");
       rows = ui->tableComponentAliases->rowCount();
       cols = ui->tableComponentAliases->columnCount();
    
       for (int ptrRow = 0; ptrRow <= rows; ptrRow++) {
           userConfigs.beginWriteArray(QString::number(ptrRow));
    
           for (int ptrCol = 0; ptrCol <= cols; ptrCol++) {
    
               if (ui->tableComponentAliases->item(ptrRow, ptrCol)) {
                   userConfigs.setArrayIndex(ptrRow);
                   userConfigs.setValue(QString::number(ptrRow)+QString::number(ptrCol), ui->tableComponentAliases->item(ptrRow, ptrCol)->text());
                   if (debugConfigs) {
                       qDebug() << "BoM: ComponentAliases: row" << ptrRow << "col" << ptrCol << ":"
                       << ui->tableComponentAliases->item(ptrRow, ptrCol)->text();
                   }
               }
    
           }
    
           userConfigs.endArray();
           if (debugConfigs) qDebug() << "---------";
       }
    
       userConfigs.endGroup(); // ComponentAliases
    

    What I'm shooting for is the output to be the table's row#\column#\value.
    Here is the output I'm getting:

    [BomConfiguration]
    ComponentAliases\0\1\00=c
    ComponentAliases\0\1\01=cap
    ComponentAliases\0\1\02=capacitor
    ComponentAliases\0\1\03=c_small
    ComponentAliases\0\size=1
    ComponentAliases\1\2\10=r
    ComponentAliases\1\2\11=res
    ComponentAliases\1\2\12=resistor
    ComponentAliases\1\2\13=r_small
    ComponentAliases\1\size=2
    ComponentAliases\10\size=0
    ComponentAliases\2\3\20=sw
    ComponentAliases\2\3\21=switch
    ComponentAliases\2\size=3
    ComponentAliases\3\4\30=l
    ComponentAliases\3\4\31=inductor
    ComponentAliases\3\4\32=l_small
    ComponentAliases\3\size=4
    ComponentAliases\4\5\40=zener
    ComponentAliases\4\5\41=zenersmall
    ComponentAliases\4\5\42=
    ComponentAliases\4\5\43=
    ComponentAliases\4\size=5
    ComponentAliases\5\6\50=d
    ComponentAliases\5\6\51=diode
    ComponentAliases\5\6\52=d_small
    ComponentAliases\5\size=6
    ComponentAliases\6\size=0
    ComponentAliases\7\size=0
    ComponentAliases\8\size=0
    ComponentAliases\9\size=0
    

    The values appear to be correct, but I'm seeing what appears to be column numbers up to 6 when there's only 4 columns ?

    The numbers just before the "=" sign appear to be the row and column numbers combined. Correct ?

    I don't understand the "size=n" entries. Is this normal when writing arrays with QSettings ?

    I'd greatly appreciate if someone could kindly explain and/or offer suggestions on the code. I'm reluctant to write code to read the data back in unless I can understand if these things are normal.

    Thanks in advance !

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved