Results 1 to 2 of 2

Thread: QDataWidgetMapper <=> QComboBox best practice

  1. #1
    Join Date
    Jan 2007
    Location
    The Netherlands
    Posts
    15
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QDataWidgetMapper <=> QComboBox best practice

    Hi all,

    I'm writing an application with a database back-end and I'm really stuck using QDataWidgetMapper in combination with a QComboBox.

    In my opinion the API documentation is a bit unclear about this and I couldn't find any examples.

    Anyhow, I've got 2 tables. One table has a foreign key referring to the other table. For this field I'd like to use a QComboBox.

    First of all, should I use a model with support for relations or do the id's of the foreign key suffice? Second, does QDataWidgetMapper take care of loading all available options (from the other table) into the QComboBox or should I do this? Last but not least, if I have to do this myself, what's the best way to deal with the id's of the database and the indices of the QComboBox?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDataWidgetMapper <=> QComboBox best practice

    Quote Originally Posted by saknopper View Post
    First of all, should I use a model with support for relations or do the id's of the foreign key suffice?
    Both approaches are fine.
    Second, does QDataWidgetMapper take care of loading all available options (from the other table) into the QComboBox or should I do this?
    If you use a relation, it is highly probable it will do it by itself. As for ids - I'm not sure, but probably it will too (although the usability of such solution is highly questionable).
    Last but not least, if I have to do this myself, what's the best way to deal with the id's of the database and the indices of the QComboBox?
    If you have to do it yourself, you can set a model for the combobox to fetch the options from. Then you'll only have to connect it to the widget mapper (or whatever other solution you want) to update the actual model if you choose another item in the combobox.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.