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. Data mapping to a QComboBox
Forum Updated to NodeBB v4.3 + New Features

Data mapping to a QComboBox

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k 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.
  • S Offline
    S Offline
    scarleton
    wrote on last edited by
    #1

    I am working on an invoice edit dialog. There is an invoice model that has only one row, the current order. One of the fields is payment type. On the UI, a QComboBox is used to allow the user to select the payment type. There is a table that simply contains the different payment types, having a PK and a name. The problem is that the name is being inserted into the invoice table, not the PK. Here is the code that I have:

    The Payment table:
    @CREATE TABLE Payment_Type (
    Payment_Type_Id INTEGER PRIMARY KEY AUTOINCREMENT,
    Payment_Type_Name VARCHAR(64) NOT NULL
    )@

    My Code:
    @
    _paymentTypeModel = new PaymentTypeModel(this, _db);

    ui.paymentTypeComboBox->setModel(_paymentTypeModel);
    ui.paymentTypeComboBox->setModelColumn(_paymentTypeModel->paymentTypeNameNo());

    /* snip a lot of code */
    _invoiceMapper->addMapping(ui.paymentTypeComboBox, _invoiceModel->paymentTypeIdNo());
    @

    I am thinking that I need to use the other version of addMapping and tell it to use the Payment_Type_Id. Or do I need to do something else?

    (P.S. I am using SQLite which is why the the string is being saved into an INTEGER field)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stevenceuppens
      wrote on last edited by
      #2

      QDataWidgetMapper is wat you need!

      Steven CEUPPENS
      Developer / Architect
      Mobile: +32 479 65 93 10

      1 Reply Last reply
      0
      • S Offline
        S Offline
        scarleton
        wrote on last edited by
        #3

        Well, I am using a QDataWidgetMapper, the _invoiceMapper is exactly that... I am wiring it up with this line of code:

        @_invoiceMapper->addMapping(ui.paymentTypeComboBox, _invoiceModel->paymentTypeIdNo());@

        Were are you suggesting I use the QDataWidgetMapper?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stevenceuppens
          wrote on last edited by
          #4

          I think this post can be useful

          http://doc.qt.digia.com/qq/qq21-datawidgetmapper.html

          Steven CEUPPENS
          Developer / Architect
          Mobile: +32 479 65 93 10

          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