Results 1 to 6 of 6

Thread: QSqlTableModel & datachanged()

  1. #1
    Join Date
    May 2010
    Posts
    9
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11

    Default QSqlTableModel & datachanged()

    Hi everyone,

    I have a QSqlTableModel with an "OnFieldChange" editStrategy and use the
    "dataChanged" signal to tidy up my gui.

    This works fine when I change the data in my model programmatically.
    But if I change the data through a connected QTableView the event gets never fired.

    2 Questions:
    1. Is this normal behavior?
    2. And if its, is there any other signal I could connect to (maybe something from the view...) ?

    thanx for any help

    Joerg

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlTableModel & datachanged()

    Had a look at the sql/tablemodel example and if not, does it do what you need?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    May 2010
    Posts
    9
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11

    Default Re: QSqlTableModel & datachanged()

    Hello franz,

    thanx for responding.

    Quote Originally Posted by franz View Post
    Had a look at the sql/tablemodel example and if not, does it do what you need?
    Yeah, I know the example, and basicly it does the same as I'am doing with my model here, but with
    one significant difference. It's on an "OnManualSubmit" editStrategie, means data gets only saved when you do an "submitAll()" and if you do that a "dataChanged" signal gets fired.

    What I want to do is to work whit a "OnFieldChange" editStrategy, and when I do that, the mentioned Signal is missing.

    Right now, I would already be grateful if somebody could confirm that this behavior is normal (even though I didn't discover something like that in the documentation) and I simply misunderstood the concept, or this is irregular and worth more debugging time.

    Any guess?

    regards

    Joerg

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,552
    Thanks
    13
    Thanked 1,579 Times in 1,508 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlTableModel & datachanged()

    Doesn't seem normal to me:
    Qt Code:
    1. #include <QtGui>
    2. #include <QtSql>
    3. #include <QDebug>
    4. #include "connection.h"
    5.  
    6. class MyTableView: public QTableView
    7. {
    8. Q_OBJECT
    9. public:
    10. MyTableView(): QTableView() {}
    11. public slots:
    12. void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
    13. { qDebug() << "dataChanged" << topLeft << bottomRight; }
    14. };
    15.  
    16. int main(int argc, char *argv[])
    17. {
    18. QApplication app(argc, argv);
    19.  
    20. if (!createConnection())
    21. return 1;
    22.  
    23. model.setTable("person");
    24. model.setEditStrategy(QSqlTableModel::OnFieldChange);
    25. model.select();
    26. MyTableView t1;
    27. t1.setWindowTitle("View 1");
    28. t1.setModel(&model);
    29. QObject::connect(&model,
    30. SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) ,
    31. &t1,
    32. SLOT(dataChanged(const QModelIndex&,const QModelIndex&)));
    33. MyTableView t2;
    34. t2.setWindowTitle("View 2");
    35. t2.setModel(&model);
    36.  
    37. t1.show();
    38. t2.show();
    39. return app.exec();
    40. }
    41. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Changes in View 2 correctly update View 1 using dataChanged()

  5. #5
    Join Date
    May 2010
    Posts
    9
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11

    Default Re: QSqlTableModel & datachanged()

    Thanks ChrisW67,

    that was what I needed to know, if this is working for you, then I
    will go one step further, trying to get this up and running over here.
    I'll post back if I make any progress.

    regards

    Joerg

  6. #6
    Join Date
    May 2010
    Posts
    9
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11

    Default Re: QSqlTableModel & datachanged()

    Hi all,

    right now I think this all complies too http://bugreports.qt.nokia.com/browse/QTBUG-1945

    This would fit for me cause I'am limited to update QT for I'am using QTJambi.

    I'am testing this out shortly,

    Bye

    Joerg

Similar Threads

  1. Clarification about dataChanged
    By airbites in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 16:02
  2. QAbstractTreeModel & dataChanged()
    By tntcoda in forum Qt Programming
    Replies: 2
    Last Post: 3rd June 2009, 00:12
  3. QSqlTableModel
    By codeman in forum Qt Programming
    Replies: 7
    Last Post: 4th May 2009, 11:04
  4. dataChanged does not re-sort the view
    By alex9099 in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2008, 20:14
  5. questions about datachanged() in model/view programming
    By calmspeaker in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 23:48

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