Results 1 to 5 of 5

Thread: Problems with QSqlRelationalTableModel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    5

    Default Re: Problems with QSqlRelationalTableModel

    Hi, sorry for the late reply to this post but I was struggling with the same problem and think I have worked out the solution.

    The problem seems to be that the QDataWidgetMapper doesn't re-populate itself correctly after updates to the model when the submit policy is QDataWidgetMapper::AutoSubmit. This is true of both the standard item delegate and the QSqlRelationalDelegate (which just calls the standard delegate if it is not populating a combo box anyway).

    To get a QLineEdit to work well with a QDataWidgetMapper and a QRelationalTableModel it is necessary to subclass either QItemDelegate or QSqlRelationalDelegate as follows:
    Qt Code:
    1. void MyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    2. {
    3. if (!strcmp(editor->metaObject()->className(),"QLineEdit")) {
    4. QLineEdit *le = qobject_cast<QLineEdit *>(editor);
    5. le->setText(index.data().toString());
    6. }
    7. else
    8. QItemDelegate::setEditorData(editor, index);
    9. }
    To copy to clipboard, switch view to plain text mode 
    Then install MyItemDelegate in the same way as you installed QSqlRelationalDelegate:
    Qt Code:
    1. mapper->setItemDelegate(new MyItemDelegate);
    To copy to clipboard, switch view to plain text mode 
    Hope this helps someone, or if I have got something wrong I would be happy to hear why.
    Last edited by certqt; 3rd December 2010 at 15:12. Reason: Corrected typo

Similar Threads

  1. problems creating toolbar...(do see the attachment)!
    By sumit in forum Qt Programming
    Replies: 15
    Last Post: 10th September 2008, 11:23
  2. Problems with scope and C header functions
    By waldowoc in forum Newbie
    Replies: 5
    Last Post: 5th August 2008, 11:29
  3. flicker and wierd resize problems ...
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2008, 18:00
  4. Replies: 2
    Last Post: 8th March 2007, 22:22

Tags for this Thread

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.