Results 1 to 4 of 4

Thread: Get data from a QTableView

  1. #1
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Get data from a QTableView

    Hi,

    When using a model/view aproach i do ...
    Qt Code:
    1. view->edit(index);
    To copy to clipboard, switch view to plain text mode 
    ... changes will not make efect until i press "Return" or, if i want i can quit with Esc. Right?

    Now suppose i have columns A, B, and C, where A is a Primary key in the database associated with the model.
    I intend to validate that key with a beforeInsert SIGNAL.

    Until here it's ok but ... now for the stupid question ... how do i get the value from column A in the row i'm editing?!

    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Get data from a QTableView

    Check this SIGNAL.. void dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight )

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

    graciano (19th January 2010)

  4. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get data from a QTableView


  5. The following user says thank you to aamer4yu for this useful post:

    graciano (19th January 2010)

  6. #4
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Get data from a QTableView

    Not 100% elegant ... but it works like this!
    Qt Code:
    1. void CidadaoDialog::antesDeInserirCidadao(QSqlRecord &registo)
    2. {
    3. QSqlQuery query;
    4. QString comando;
    5. int lin, col;
    6. QVariant conteudoDaChave;
    7. lin = vistaCidadao->currentIndex().row();
    8. col = 0;
    9. conteudoDaChave = modeloCidadao->index(lin, col, QModelIndex()).data(Qt::EditRole);
    10. comando = "SELECT * FROM Cidadao WHERE idCidadao = " + conteudoDaChave.toString()+";";
    11. query.prepare(comando);
    12. query.exec();
    13. if(query.next())
    14. {
    15. msg.setText("Chave duplicada(duplicate key)!");
    16. msg.setInformativeText(query.lastQuery());
    17. msg.exec();
    18. modeloCidadao->select();
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    What i was looking for is in line 9.

    Thanks

Similar Threads

  1. QTableView does not show data
    By waynew in forum Newbie
    Replies: 4
    Last Post: 11th December 2009, 23:38
  2. Insert data to QTableView
    By Lodhart in forum Qt Programming
    Replies: 1
    Last Post: 23rd April 2009, 09:38
  3. how to get data from cell of QTableview
    By yleesun in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 14:31
  4. QTableView and reimplement data
    By estanisgeyer in forum Qt Programming
    Replies: 6
    Last Post: 7th May 2008, 18:18
  5. finding data in a qtableview
    By JeanC in forum Newbie
    Replies: 4
    Last Post: 7th March 2008, 19:36

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.