Results 1 to 2 of 2

Thread: Yet another QSqRelationalTableModel QDataWidgetMapper QComboBox problem

  1. #1
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Yet another QSqRelationalTableModel QDataWidgetMapper QComboBox problem

    I am struggling for few days now at what seems to be already answered, but i cant find answer for my situation
    I am trying to create CRUD form
    I have QSqlRelationalTableModel connected to QTableView
    Qt Code:
    1. m_table->setTable(m_tableName);
    2. m_table->setJoinMode(QSqlRelationalTableModel::LeftJoin);
    3. m_table->select();
    4. ui->table->setModel(m_table);
    To copy to clipboard, switch view to plain text mode 
    the same model is connected to QDataWidgetMapper, and mapper is connected to qtableview selection model
    Qt Code:
    1. mapper = new QDataWidgetMapper(this);
    2. mapper->setItemDelegate(new QSqlRelationalDelegate);
    3. mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
    To copy to clipboard, switch view to plain text mode 
    I create edit form with comboboxes dynamiclly for each field if there is relation
    Qt Code:
    1. if(m_table->relationModel(fieldIndex)){
    2. QComboBox *cb = new QComboBox();
    3. cb->setModel(m_table->relationModel(fieldIndex));
    4. cb->setModelColumn(m_table->relationModel(fieldIndex)->fieldIndex("name"));
    5. mapper->addMapping(cb, fieldIndex);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Whenn i try to edit record with
    mapper->submit()
    it returnes false, like there is error, but m_table->lastError() is empty, and data is submitted to database!?!?
    The strangest thing is that after submit, the table (qtableview) shows key value instead of text value from relational table for submitted row, until i re-select model
    What am i doing wrong?

  2. #2
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Yet another QSqRelationalTableModel QDataWidgetMapper QComboBox problem

    anyone has idea why would mapper->submit() return false,
    and lastError() is empty
    but the data is submited todatabase?

    QSqlRelationalTableModel has editStrategy OnFieldChange
    mapper submits onManualSubmit

Similar Threads

  1. QDataWidgetMapper and QComboBox troubles
    By thec0der in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2011, 09:59
  2. QDataWidgetMapper and QComboBox
    By buckadl in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2010, 21:40
  3. QDataWidgetMapper and QComboBox
    By scarleton in forum Qt Programming
    Replies: 4
    Last Post: 7th November 2010, 14:28
  4. QDataWidgetMapper and QComboBox
    By mazurekwrc in forum Qt Programming
    Replies: 0
    Last Post: 31st March 2009, 13:02
  5. QDataWidgetMapper and QCombobox
    By miraks in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2008, 17:53

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.