Results 1 to 1 of 1

Thread: Weird behavior with QSqlRelationalTableModel & setFilter

  1. #1
    Join Date
    Jun 2011
    Qt products
    Qt4 Qt5

    Default Weird behavior with QSqlRelationalTableModel & setFilter

    I have a weird problem with QSqlRelationalTableModel.
    In Constructor my model&view initialize with this source:

    Qt Code:
    1. // Create db model
    2. model = new QSqlRelationalTableModel(ui->viewTableReport);
    3. model->setTable("reports");
    5. // Set headerData
    6. model->setHeaderData(model->fieldIndex("customer_id"), Qt::Horizontal, tr("Name"));
    7. model->setHeaderData(model->fieldIndex("tottal"), Qt::Horizontal, tr("Tottal"));
    8. model->setHeaderData(model->fieldIndex("created"), Qt::Horizontal, tr("Created"));
    10. // Set Relations to the other database tabels
    11. model->setRelation(model->fieldIndex("customer_id"), QSqlRelation("customers", "id", "name"));
    13. // Set edit strategy
    14. model->setEditStrategy(QSqlRelationalTableModel::OnFieldChange);
    16. // Populate the model
    17. /*
    18.   * Problem is here, on setFilter
    19.   */
    20. //model->setFilter("hidden=FALSE");
    21. model->select();
    23. // Set the model and hide the ID column
    24. ui->viewTableReport->setModel(model);
    26. // Customize data view
    27. ui->viewTableReport->setColumnHidden(model->fieldIndex("id"), true);
    28. ui->viewTableReport->setColumnHidden(model->fieldIndex("hidden"), true);
    To copy to clipboard, switch view to plain text mode 

    When i uncomment setFilter the QTableView shown nothing,it mean empty
    Of course i have a lot record with "hidden=FALSE"
    But weird section is here:
    When i comment model->setRelation() everythings going be fine :0
    I mean when i unset relations with other tables it's working pretty and those record with "hidden=FASE" clause just shown!
    And i have couple of model, but those working sweet with relational, even with "customers" table.

    Any idea for this situation?

    Thank you!

    After posting this thread i found duplicate thread, i don't know it's i can solved with that solution.
    It's my bad to posting duplicate.
    but shoulda check is working or not.
    Last edited by Alir3z4; 11th July 2011 at 06:22.
    ...یه مرد هیچوقت زمین نمیخوره

Similar Threads

  1. QWebview weird behavior on some pages
    By ZaQ in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2011, 03:24
  2. QWebView weird behavior !!
    By gontham in forum Newbie
    Replies: 1
    Last Post: 21st October 2010, 14:00
  3. Weird removeRow behavior
    By metalinspired in forum Qt Programming
    Replies: 0
    Last Post: 30th August 2009, 12:42
  4. trouble with QSqlRelationalTableModel and setFilter
    By yleesun in forum Qt Programming
    Replies: 5
    Last Post: 3rd March 2009, 07:02
  5. Weird QMenu behavior on Mac
    By munna in forum Qt Programming
    Replies: 1
    Last Post: 14th January 2009, 15:18

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.