Results 1 to 3 of 3

Thread: how to clear relationship

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default how to clear relationship

    Hi !

    I created a class for editing database tables (SQLITE) with the relationship ( LEFT JOIN ) to another table with enable NULL for FK.
    Example:
    master table:
    driver:
    ID, NAME, CAR
    subtable:
    cars:
    ID, TYPE, COLOR
    Here is a snippet of code:

    Qt Code:
    1. ...
    2. rtblmdl = new QSqlRelationalTableModel(this,ggdb);
    3. ...
    4. rtblmdl->setTable("driver");
    5. rtblmdl->setRelation(2,QSqlRelation("cars","id","car"));
    6. rtblmdl->setJoinMode(QSqlRelationalTableModel::LeftJoin);
    7. rtblmdl->setEditStrategy(QSqlTableModel::OnManualSubmit);
    8.  
    9. ...
    10. // join to QTableView ( tblW )
    11. ui->tblW->setModel(mrtblmdl);
    12. ui->tblW->setItemDelegate(new QSqlRelationalDelegate(ui->tblW));
    13. ui->tblW->hideColumn(0);
    14. ...
    15.  
    16.  
    17.  
    18. ...
    19. // set record "QSqlRecord" ( rec is private variable ) after editting
    20. rec.setValue(i,lnEdt[i]->text());
    21. ...
    22. // write in to table
    23. rtblmdl->setRecord(ui->tblW->currentIndex().row(),rec);
    24. rtblmdl->submitAll();
    25. ...
    26. // write into table another method
    27. rtblmdl->setData(rtblmdl->index(ui->tblW->currentIndex().row(),5),QVariant::fromValue(1));
    28. rtblmdl->submitAll();
    To copy to clipboard, switch view to plain text mode 



    The cells of the master table ( "driver" ) I do not editing by qtableview, but separate EditBoxs (one EditBox for each column ).
    However, if I need erase cell with FK (cancel a relationship), i setting the appropriate item in QSqlRecord to NULL, this value after call methods QSqlRelationalTableModel.SubmitAll not write ( not delete relationship )
    I also tried writing by QSqlRelationalTableModel.setData unfortunately with the same result.

    Thanks fro any response.
    Last edited by milos1; 27th July 2015 at 12:00.

Similar Threads

  1. Facebook Relationship Visualization
    By Sven in forum Qt-based Software
    Replies: 3
    Last Post: 10th November 2014, 13:26
  2. what's the relationship between QOCI and OCI ?
    By silentyears in forum Qt Programming
    Replies: 6
    Last Post: 14th March 2014, 13:29
  3. Replies: 1
    Last Post: 18th April 2012, 16:35
  4. How to get the relationship between two QDockWidget?
    By yunxiaodong in forum Qt Programming
    Replies: 0
    Last Post: 16th August 2011, 08:32
  5. Relationship b/w different classes
    By salmanmanekia in forum Newbie
    Replies: 0
    Last Post: 2nd June 2010, 18:24

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.