Results 1 to 2 of 2

Thread: Empty qsqlrelationaltablemodel

  1. #1
    Join Date
    Jul 2015
    Qt products
    MacOS X Windows

    Exclamation Empty qsqlrelationaltablemodel

    When I put model->select(); after relations, the model is empty, when I put it back before relations, the table displays correctly, but when I edit any cell the whole row becomes empty and gets "!" on the left. No errors.

    Qt Code:
    1. model->setTable("syllabi");
    2. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    3. model->select();
    4. model->setRelation(3, QSqlRelation("activity_types", "activity_type_id", "activity_type_name"));
    5. model->setRelation(0, QSqlRelation("teachers", "teacher_id", "teacher_name"));
    6. //model->select();
    7. qDebug() << model->lastError();
    9. ui->tableView->setModel(model);
    10. ui->tableView->setItemDelegate(new QSqlRelationalDelegate(ui->tableView));
    11. ui->tableView->horizontalHeader()->setStretchLastSection(true);
    12. ui->tableView->setColumnHidden(9, true);
    To copy to clipboard, switch view to plain text mode 
    Last edited by Charlie42; 17th July 2015 at 13:55.

  2. #2
    Join Date
    Mar 2009
    Brisbane, Australia
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Unix/X11 Windows
    Wiki edits

    Default Re: Empty qsqlrelationaltablemodel

    If adding the related tables causes the rows to disappear it is probably because the value in the main table column is not present in the related table. Impossible to say without seeing the data.

    If editing the row causes it to disappear then possibly the main table does not have a primary key (See

Similar Threads

  1. How to put empty value in QDateEdit?
    By sawerset in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2019, 22:06
  2. is QString empty?
    By timmu in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2010, 23:17
  3. Status Bar Empty
    By waynew in forum Newbie
    Replies: 5
    Last Post: 22nd November 2009, 14:01
  4. QTreeView is empty
    By t0bias in forum Qt Programming
    Replies: 2
    Last Post: 31st August 2008, 12:22
  5. remove directory empty or not empty
    By raphaelf in forum Newbie
    Replies: 12
    Last Post: 27th October 2006, 08:30

Tags for this Thread


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.