Results 1 to 3 of 3

Thread: Troubleshooting QDataWidgetMapper to work with QComboBox

  1. #1
    Join Date
    Feb 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Troubleshooting QDataWidgetMapper to work with QComboBox

    Good day to all,

    I know this issue has been posted before but i could not find a suitable answer.
    The problem is this :
    I have a QDataWidgetMapper with the model set to a QSortFilterProxyModel that filters a QSqlRelationalTableModel.
    Qt Code:
    1. model= new QSqlRelationalTableModel(this);
    2. filter= new QSortFilterProxyModel(this);
    3. filter->setSourceModel(model);
    4. model->setTable("patients");
    5. model->setRelation(3,QSqlRelation("doctors","doctor_id","doctor_name"));
    6. model->select();
    To copy to clipboard, switch view to plain text mode 

    the data stored in the model comes from a" medical patients " tabel in witch the a field doctor_id is linked to primary key in doctors table like this

    patients table :
    ================================================== =======
    name [text] |condition [text] | treatment [text] |doctor_id [integer]
    ================================================== =======

    doctors table:
    ==============================
    doctor_id[integer] | doctor_name [text]
    ==============================

    It's pretty straight forward right.
    I filter the model by field name to make make the user's selection easier

    Next I apply a mapper:
    Qt Code:
    1. mapper = new QDataWidgetMapper(this);
    2. mapper->setModel(filter);
    3. mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    To copy to clipboard, switch view to plain text mode 

    I mapped all other field to text edit widgets but I needed a combo box to select a doctor_name

    Qt Code:
    1. QSqlTableModel* doctors= model->relationModel(model->fieldIndex("doctor_id "));
    2. comboBox->setModel(tabelMedici);
    3. comboBox->setModelColumn(tabelMedici->fieldIndex("doctor_name"));//populates the combo box with the names
    4. mapper->addMapping(comboBox,model->fieldIndex("doctor_id "));
    To copy to clipboard, switch view to plain text mode 

    Finaly i need to navigate the model in a tableViewer

    Qt Code:
    1. tableView->setModel(filter);
    2. connect(tableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
    3. mapper, SLOT(setCurrentModelIndex(QModelIndex)));
    To copy to clipboard, switch view to plain text mode 

    when i do a selection in tableView all the text widgets change values in accordance except comboBox witch doesn't change anything.

    The combo box gets populated but is doesn't automatically change selection to the relevant field value.

    What am I missing here?
    Any suggestions?

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

    Default Re: Troubleshooting QDataWidgetMapper to work with QComboBox

    You'll probably end up having to implement your own delegate for this with proper implementations of setModelData() and setEditorData().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Troubleshooting QDataWidgetMapper to work with QComboBox

    OK ..so i figured it out. It seems that the mapper does not work properly on a sortfiltermodel , well at least not with the default QSqlRelationalDelegate.
    Trying to reimplement QSqlRelationalDelegate to see what can be done.
    I will post if results are favorable.

Similar Threads

  1. QDataWidgetMapper and QComboBox
    By buckadl in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2010, 21:40
  2. QDataWidgetMapper and QComboBox
    By scarleton in forum Qt Programming
    Replies: 4
    Last Post: 7th November 2010, 14:28
  3. QDataWidgetMapper and QComboBox
    By mazurekwrc in forum Qt Programming
    Replies: 0
    Last Post: 31st March 2009, 13:02
  4. QDataWidgetMapper and QCombobox
    By miraks in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2008, 17:53
  5. QDataWidgetMapper <=> QComboBox best practice
    By saknopper in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2007, 10:50

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.