Results 1 to 5 of 5

Thread: QDataWidgetMapper AutoSubmit

  1. #1
    Join Date
    May 2009
    Location
    Memphis, TN
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QDataWidgetMapper AutoSubmit

    QDataWidgetMapper Qt Documentation: "AutoSubmit" will update the model as soon as the current widget loses focus."

    What exactly does "loses focus" mean?

    When I update a field in my form it calls the "setModelData" function the first time but if I re-enter the same field and try to update it again -- the "setModelData" is NOT called to update to the new value.

    Can someone explain when the QDataWidgetMapper is supposed to update the model in "AutoSubmit" mode?

    Do most people use AutoSubmit? (I am sure Manual Submit will work, but AutoSubmit would be cleaner -- no button press required.)

    Thanks, Jeff.

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QDataWidgetMapper AutoSubmit

    Expected behaviour is that when you click inside a cell, edit starts. When you click outside, so editor widget looses focus, the model should be updated. Qt comes with an example how to use the QDataWidgetMapper. See examples/itemviews/simplewidgetmapper and see whether it behaves the same.
    It's nice to be important but it's more important to be nice.

  3. The following user says thank you to axeljaeger for this useful post:

    jeffpogo (20th January 2010)

  4. #3
    Join Date
    May 2009
    Location
    Memphis, TN
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDataWidgetMapper AutoSubmit

    Thanks!

    I got it working ... I had a bad signal call in my setEditorData function.

    Jeff.

  5. #4
    Join Date
    May 2009
    Location
    Memphis, TN
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDataWidgetMapper AutoSubmit

    The QDataWidgetMapper/QSqlTableModel/AutoSubmit combination do not seem to work together as expected. When you change focus, sometimes the model gets updated, sometimes it does not. (Usually the first field gets updated -- the first time and the others do not.)

    I might be able to get my form working correctly with the suggestion in QTBUG-1086. (I might try it.)

    I would venture that most people code there own form mapping solution.

    I learned a lesson ... when something is not working as you expect check: http://bugreports.qt.nokia.com/browse -- it can save a lot of time.

    If someone does have some successful QDataWidgetMapper/QSqlTableModel code they would like to share, I would love to check it out because I like the concept.

  6. #5
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDataWidgetMapper AutoSubmit

    I had some trouble with the QDataWidgetMapper/QSqlTableModel. I'm using them in manualsubmit mode as the auto mode has some weirdness as you indicated.

    What worked for me is the following:

    Qt Code:
    1. //inside constructor
    2. model = new QSqlTableModel;
    3. model->setTable("unit");
    4. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    5.  
    6. model->select();
    7. model->sort(3,Qt::AscendingOrder);
    8.  
    9. mapper = new QDataWidgetMapper(this);
    10. mapper->setModel(model);
    11. mapper->addMapping(ui->le_Unit, model->fieldIndex("UnitName"));
    12.  
    13. ....
    14.  
    15. //inside a method where I make some changes to the mapped items
    16. mapper->submit();
    17. model->submitAll();
    To copy to clipboard, switch view to plain text mode 

    hope this helps

Similar Threads

  1. QDataWidgetmapper
    By locus in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2012, 11:24
  2. QDataWidgetMapper and QComboBox
    By mazurekwrc in forum Qt Programming
    Replies: 0
    Last Post: 31st March 2009, 13:02
  3. QDataWidgetMapper
    By rogerholmes in forum Newbie
    Replies: 4
    Last Post: 24th March 2009, 19:32
  4. QDataWidgetMapper and QCombobox
    By miraks in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2008, 17:53
  5. QDataWidgetMapper and QLineEdit
    By GuL in forum Newbie
    Replies: 3
    Last Post: 13th August 2008, 14:58

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.