Results 1 to 4 of 4

Thread: TableView + SqlQueryModel: can't insert or edit rows

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default TableView + SqlQueryModel: can't insert or edit rows

    Hi,
    I have a problem editing or inserting rows in a QTableView + QSqlQueryModel.

    Here my code:

    Qt Code:
    1. MainDialog::MainDialog(QWidget *parent)
    2. :QDialog(parent)
    3. {
    4. ...
    5. scoopsModel = new QSqlQueryModel;
    6. scoopsModel->setQuery("SELECT numero,pagina,sottotitolo FROM elenco_scoop WHERE id_gioco="
    7. + articlesComboBox->itemData(articlesComboBox->currentIndex()).toString()
    8. + " ORDER BY numero");
    9. scoopsModel->setHeaderData(0, Qt::Horizontal, tr("Numero"));
    10. scoopsModel->setHeaderData(1, Qt::Horizontal, tr("Pagina"));
    11. scoopsModel->setHeaderData(2, Qt::Horizontal, tr("Sottotitolo"));
    12. scoopsTableView->setModel(scoopsModel);
    13. scoopsTableView->show();
    14.  
    15. connect(scoopAddButton, SIGNAL(clicked()), this, SLOT(addScoop()));
    16. ...
    17. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void MainDialog::addScoop()
    2. {
    3. ((QSqlQueryModel*)scoopsTableView->model())->insertRows(((QSqlQueryModel*)scoopsTableView->model())->rowCount(), 1);
    4. }
    To copy to clipboard, switch view to plain text mode 

    1) First problem: if I double click a cell of a row it doesn't switch in edit mode;
    2) Second problem: when clicking scoopAddButton no new row is inserted; insertRows(..) returns false.

    Where is the error?

    Thanks
    Giuseppe CalÃ

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: TableView + SqlQueryModel: can't insert or edit rows

    Hi,

    I guess you need a QSqlTableModel. QueryModel is read only, I suppose.

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: TableView + SqlQueryModel: can't insert or edit rows

    Why list this function among QSqlQueryModel's members if it doesn't work?

    Regards
    Giuseppe CalÃ

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: TableView + SqlQueryModel: can't insert or edit rows

    Quote Originally Posted by jiveaxe View Post
    Why list this function among QSqlQueryModel's members if it doesn't work?
    QSqlQueryModel docs don't list it. This method exists, because it was inherited from QAbstractItemModel.

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.