Results 1 to 6 of 6

Thread: Updating a data in QTableView question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Updating a data in QTableView question

    Hi to all, especialy nearly divine entities like jacek, jpn, marcel, wysota and others!

    So, like I said, I have a shopping cart of merchandize in QTableView. Record are now added as they should, but I bumped into following problem. Let's say the shopping cart contains:
    Qt Code:
    1. +========================+
    2. + Coca Cola +
    3. + 1,00 1x 1.00 +
    4. +------------------------+
    5. + Sprite +
    6. + 2.44 1x 2.44 +
    7. +========================+
    To copy to clipboard, switch view to plain text mode 
    Now, the user chooses another sprite and instead of:
    Qt Code:
    1. +========================+
    2. + Coca Cola +
    3. + 1,00 1x 1.00 +
    4. +------------------------+
    5. + Sprite +
    6. + 2.44 1x 2.44 +
    7. +------------------------+
    8. + Sprite +
    9. + 2.44 1x 2.44 +
    10. +========================+
    To copy to clipboard, switch view to plain text mode 
    I would like updated quantity and subtotal (second line, second number is quantity, third number is subtotal) like this:
    Qt Code:
    1. +========================+
    2. + Coca Cola +
    3. + 1,00 1x 1.00 +
    4. +------------------------+
    5. + Sprite +
    6. + 2.44 2x 4.88 +
    7. +========================+
    To copy to clipboard, switch view to plain text mode 
    Now, here is a code chunck that should do this:
    Qt Code:
    1. else
    2. {
    3. // merchandize found, update quantity and subtotal
    4. qDebug() << "iRemberedMerchandizeID:" << iRemberedMerchandizeID; // debug output
    5. CMerchandizeOrder* pUpdatedOrder=new CMerchandizeOrder(order); // gets order to update
    6. Q_CHECK_PTR(pUpdatedOrder); // checks creation
    7. structOrder updatedOrderStruct=pUpdatedOrder->orderValues(); // gets order's struct
    8.  
    9. updatedOrderStruct.iMerchandizeQuantity++; // increase quantity
    10. updatedOrderStruct.rSubtotal=updatedOrderStruct.iMerchandizeQuantity*updatedOrderStruct.rMerchandizePrice; // updates subtotal
    11. pUpdatedOrder->setMerchandizeQuantity(updatedOrderStruct.iMerchandizeQuantity);
    12. pUpdatedOrder->setSubtotal(updatedOrderStruct.rSubtotal);
    13. pUpdatedOrder->setDisplayString(updatedOrderStruct);
    14. m_pShoppingCartModel->orders().replace(iRememberedIndex, pUpdatedOrder);
    15. QModelIndex index=shoppingCartModel()->index(0, 0, QModelIndex());
    16. shoppingCartModel()->setData(index,
    17. pUpdatedOrder->orderValues().strDisplayString,
    18. Qt::EditRole);
    19. emit dataChanged(index, index);
    20. }
    21. // TODO: update grand total field
    To copy to clipboard, switch view to plain text mode 
    but the cell is not updated, i.e., nothing happens. The code is a part of bigger if clause, and I've set breakpoint in the begining of this code chunk to check if the IF clause works ok. It does. I've checked with debugger, data are recalculated correctly (quantity and subtotal), but the contenst of QTableView are not updatet. Why?!
    Last edited by MarkoSan; 28th May 2008 at 21:18. Reason: spelling error
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. QTableView and its Scrollbar question
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 28th May 2008, 14:23
  2. QTableview data display font question
    By MarkoSan in forum Newbie
    Replies: 8
    Last Post: 14th May 2008, 12:57
  3. QTableView - data() - item
    By starcontrol in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 14:41
  4. finding data in a qtableview
    By JeanC in forum Newbie
    Replies: 4
    Last Post: 7th March 2008, 19:36
  5. QTableView Question
    By kandalf in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2007, 18:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.