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. updating a column rows (condition Barcode) using QMap<QString,Int>

updating a column rows (condition Barcode) using QMap<QString,Int>

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidgetqmapupdatingcolumn
3 Posts 2 Posters 503 Views
  • 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.
  • P Offline
    P Offline
    Proton Phoenix
    wrote on 19 Feb 2022, 23:33 last edited by Proton Phoenix
    #1

    Hi ~~
    I have a problem Scanning Barcodes ... I want when the user scan a product twice or more it i will add +1 to the quantity column of that product (Barcode,QR Code) each time even if the user scan it and scan other products and he scan it again ..
    note: i don't have problem receiving data from barcode scanner

    QMap<QString,int> countOfStrings;
    
    
         for(int i=0;i<BarcodeScanValues.count();i++)
         {
             countOfStrings[BarcodeScanValues[i]]++;
         }
    qDebug()<<countOfStrings;
    
        qDebug()<<countOfStrings.values();
    
        qDebug()<<countOfStrings.keys();
    
        ProductCounter=countOfStrings.values();  // QStringList
        productBarcode=countOfStrings.keys();
    
    /* 
    ("7613036309493", "4600680000640", "8133578000377", "7613036445818", "7613036445818")
    
    
    QMap(("4600680000640", 1)("8133578000377", 1)("7613036309493", 1)("7613036445818", 2))
    
    
    (1, 1, 1, 2)
    ("4600680000640", "6133978000377", "7613036309493", "7613036445818")
    

    */

    any idea about this algorithm how to use this to update QTablewidget ? many thanks <3
    ![](e819b5ba-bc31-4c99-94d2-7f0a31412cc3-image.png

    this picture is quite similar to the one i have only i don't have widget all are QTablewidget cells and i have a Barcode column so the algorithm should find the barcode inside the table if it's already exist it add +1 to it's row quantity and it update the price ...
    any advices? or i must save as temp database? then updating values?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 20 Feb 2022, 00:01 last edited by
      #2

      QTableWidget maintains an internal QAbstractItemModel that contains the data that is being presented. You can use QAbstractItemModel::match() to find the QModelIndex of items matching a value. So, something like this (untested):

      QAbstractItemModel *model = tableWidget->model();
      
      QModelIndex startIndex = model->index(0, barcodeColumnNumber);
      QModelIndexList matches = model->match(startIndex, Qt::EditRole, barcodeValue, 1, Qt::MatchExactly);
      if (matches.count() > 0) {
        QModelIndex match = matches.at(0);
        match = match.siblingAtColumn(countColumn);
        int count = match.data(Qt::EditRole).toInt() + 1;
        model->setData(match, count);
      }
      
      1 Reply Last reply
      2
      • P Offline
        P Offline
        Proton Phoenix
        wrote on 20 Feb 2022, 00:06 last edited by Proton Phoenix
        #3

        Thank You so much Bro You Are Life Save I wish All the best happy life for you <3

        note : it works better than i ever imagine <3

        1 Reply Last reply
        0

        2/3

        20 Feb 2022, 00:01

        • Login

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