Results 1 to 4 of 4

Thread: Edit QTableView cell fields

  1. #1
    Join Date
    Sep 2016
    Posts
    8
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Edit QTableView cell fields

    Hello,
    i'm trying to edit a table cell of my QTablView but with no luck.
    The code of the function i'm calling to populate it is:
    Qt Code:
    1. void perito::on_pushButton_listaP_clicked()
    2. {
    3. Conn conn;
    4. conn.connectionOpen();
    5. QSqlQuery *qry = new QSqlQuery(conn.mydb);
    6. qry->prepare("SELECT * FROM perito");
    7. qry->exec();
    8. modal->setQuery(*qry);
    9. ui->tableView->setModel(modal);
    10. conn.connectionClose();
    11. }
    To copy to clipboard, switch view to plain text mode 

    The table is well populated but i'm unable to modify any cell. I have made the table with designer but the field "NoEditTriggers" is unchecked ..

    Any hints? Thanks for your time and answers

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Edit QTableView cell fields

    From the documenation of QSqlQueryModel:
    The QSqlQueryModel class provides a read-only data model for SQL result sets.
    Cheers,
    _

    P.S.: you are leaking the QSqlQuery object

  3. The following user says thank you to anda_skoa for this useful post:

    Bruschetta (30th September 2016)

  4. #3
    Join Date
    Sep 2016
    Posts
    8
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Edit QTableView cell fields

    Thanks a lot anda_skoa, i solved my problem!

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Edit QTableView cell fields

    P.S.: you are leaking the QSqlQuery object
    As well as the QSqlQueryModel. Each time you click the button, it creates each of these objects, and they never get deleted. Setting a new model on the table view does not delete the old model, it just hangs around until your program finally exits and the OS cleans up. Create the model instance as a child of "perito" and reuse it as needed for new queries. As a child of the perito instance, it will be deleted when perito is.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 21st October 2015, 18:43
  2. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  3. Replies: 2
    Last Post: 12th October 2010, 20:50
  4. QTableView showing empty fields
    By ederbs in forum Qt Programming
    Replies: 5
    Last Post: 4th October 2007, 00:30
  5. QTableView not corectly showing empty fields
    By Sergey B. in forum Qt Programming
    Replies: 4
    Last Post: 15th June 2007, 08:18

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.