Results 1 to 5 of 5

Thread: Qtableview and sql

  1. #1
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Qtableview and sql

    i'm using a Qtableview with an hiden invoice_id column to manage invoices row, i would like to know if there is a way
    to change the invoice_id column value for each row before commiting thanks in advance?

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qtableview and sql

    If you don't want to show, why to have it in first place??? QTableView works on a model. According to the logic, you can change the requisite in setData function of model. Why does it feel to me you have an overhang of lot of asp.net tables before you came here, or perhaps you just didn't explain it well enough

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qtableview and sql

    If you don't want to show, why to have it in first place???
    The obvious response is that a single model may serve multiple views and not all views necessarily need (or even should if columns are restricted to certain users) to show everything in the model. It can also be useful to have a column that is hidden in release version but visible during debug (e.g. an underlying database ID).

    i would like to know if there is a way to change the invoice_id column value for each row before commiting thanks in advance?
    You can call setData() on model indexes that reference columns that a view is not showing. You do need to work out exactly where (inside or outside the model) and when (on insert only, update only, both, what about delete or new rows as yet uncommited) the value should be changed. Inside the model: do anything you like in the model's setData(), just make sure the relevant signals are emitted so views stay synchronised. Outside the model: if you have a delegate on the table then setModelData() may be a good place. If you are referring to commiting to an underlying database then the QSqlTableModel::beforeInsert(), beforeUpdate(), and primeInsert() signals can be useful.

  4. The following user says thank you to ChrisW67 for this useful post:

    kuntagp (22nd December 2011)

  5. #4
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qtableview and sql

    Thanks Chris your post help me a lot

  6. #5
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qtableview and sql

    Here is a little example:

    model->setData(model->index(row, 1), QVariant(id));

Similar Threads

  1. QTableView and QLineEdit OUTSIDE of QTableView, like Excel
    By JoZCaVaLLo in forum Qt Programming
    Replies: 10
    Last Post: 13th May 2011, 13:20
  2. Replies: 2
    Last Post: 26th November 2009, 04:45
  3. Help QTableView
    By vinny gracindo in forum Newbie
    Replies: 1
    Last Post: 22nd November 2009, 00:44
  4. QTableView
    By jamesjara in forum Newbie
    Replies: 5
    Last Post: 26th June 2009, 06:37
  5. QTableView
    By fpujol in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2007, 08:17

Tags for this Thread

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.