Results 1 to 5 of 5

Thread: QSqlTableModel submitAll access query

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: QSqlTableModel submitAll access query

    Quote Originally Posted by wysota View Post
    Last query of what? An SQL model? Most probably through QSqlQueryModel::query()

    No the UPDATE Query by submit all..

    i found only ONE Way... connect the model an grab all data to construct a sqlquery..
    is here no other way?

    Qt Code:
    1. connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(WakeUpTable(QModelIndex,QModelIndex)));
    2.  
    3. void Mysql_Table::WakeUpTable(const QModelIndex & a , const QModelIndex & b )
    4. {
    5. if (a.isValid() && b.isValid()) {
    6.  
    7. if (model->isDirty(a) && model->isDirty(b)) {
    8. /* user mods data set new wath? */
    9. const QString fieldnametouch = FieldNameList.at(a.column());
    10. const QString indexfieldname = INDEXFIELD; /* discovery on SHOW COLUMNS FROM table + make qstringlist FieldNameList */
    11.  
    12. DirtySQL = true;
    13. if (INDEXFIELD.size() > 0) {
    14. /* QModelIndex index field */
    15. QModelIndex base = a.sibling(a.row(),indexcolumn);
    16. /* Prepare Dirty sqlupdate */
    17. const QString pending = QString("UPDATE %1 SET %2='%3' WHERE %4='%5' LIMIT 1")
    18. .arg(table)
    19. .arg(fieldnametouch)
    20. .arg(a.data().toString())
    21. .arg(INDEXFIELD)
    22. .arg(base.data(Qt::DisplayRole).toString());
    23. /* append on a list wakeup on submit ... */
    24. DirtyPendingQuery.append(pending);
    25. qDebug() << "### Pendingsql one line " << pending;
    26. qDebug() << "### WakeUpTable " << table << " fieldname active " << fieldnametouch << " - "
    27. << a.data().toString() << " - " << a.row()
    28. << "x" << a.column() << " on " << base.data(Qt::DisplayRole).toString();
    29. }
    30. }
    31. }
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 26th April 2007 at 23:51. Reason: wrapped too long line

Similar Threads

  1. Replies: 1
    Last Post: 4th October 2006, 16:05

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.