Results 1 to 2 of 2

Thread: QSQLITE database, delete rows, frozen columns

  1. #1
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    1

    Question QSQLITE database, delete rows, frozen columns

    Hello,

    I am working on the project in QT using QSQLITE database. I have a table that contains informations about the cars. I've created a QSqlTableModel object and set it in QTableView object. I want to click on a cell(mark it) in the table, push button "delete" and delete whole row which contains that cell. I've no idea how to do it. I thought about emitting signal "activated" from QTableView object. Unfortunately it doesn't work.
    Qt Code:
    1. connect(ui->tablecarsv,SIGNAL(activated(QModelIndex)),this, SLOT(do23 (QModelIndex)))
    To copy to clipboard, switch view to plain text mode 

    Next thing: How to set "read only" or frozen for column in table that is displays in QTableView?

    Thanks in advance

  2. #2
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: QSQLITE database, delete rows, frozen columns

    Hi carvi,

    I thought about emitting signal "activated" from QTableView object
    Read the documentation of QAbstractItemView::activated(const QModelIndex& index) if you want to know when it emitted. But if you want a simple solution, try this:
    1. Connect your button to a slot
    2. Then in the body of the slot, use selection model form your view to find selected items, so you can delete these items


    The code would be something like this:
    Qt Code:
    1. // connect to a slot
    2. connect(removeButton, SIGNAL(clicked()), this, SLOT(removeItems()));
    3.  
    4. .....
    5.  
    6. // slot definitions
    7. void MyWidget::removeItems()
    8. {
    9. QItemSelectionModel *selectionModel = view->selectionModel();
    10.  
    11. // ex: delete first row in selection
    12. QModelIndex index = selectionModel->selectedRows().first();
    13. tableModel->removeRow(index.row());
    14. tableModel->submit();
    15. }
    To copy to clipboard, switch view to plain text mode 

    Next thing: How to set "read only" or frozen for column in table that is displays in QTableView?
    I usually create a model that inherited from QSqlQueryModel, QSqlTableModel or QSqlRelationalTableModel, then reimplement data(), setData() and flags() method.

    Qt Query Model Example is a good place to start creating your own custom SQL model.

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

    carvi (11th April 2011)

Similar Threads

  1. QSqlite, multiple connections to in memory database.
    By adzajac in forum Qt Programming
    Replies: 9
    Last Post: 10th March 2010, 22:35
  2. QSQLITE database can't exec queries
    By mcwar in forum Qt Programming
    Replies: 5
    Last Post: 12th January 2010, 23:47
  3. QSqlite database lock + Delegate + QSqlQueryModel
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 13th October 2009, 11:52
  4. Frozen? ... no ... calling 01800 Database
    By chaosgeorge in forum Qt Programming
    Replies: 2
    Last Post: 26th November 2006, 13:06
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

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.