Results 1 to 5 of 5

Thread: Access data from QSqlTableModel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    24
    Thanked 17 Times in 14 Posts

    Red face Access data from QSqlTableModel

    Hi,

    I am very raw with model/view hence the many questions..

    On my QSqlTableModel I have the following code to present the data:

    Qt Code:
    1. QVariant maintModel::data(const QModelIndex &index, int role) const
    2. {
    3. if (role == Qt::DisplayRole)
    4. {
    5. QString var;
    6. var = record(index.row()).value("cnty_nam").toString();
    7. qDebug() << index.row() << displayColumnCode << var;
    8. return var;
    9. }
    10. return QVariant();
    11. }
    To copy to clipboard, switch view to plain text mode 

    I am just displaying one column thus I just use row. From the debug I can see that the row numbers are fine, also the column exists, but in this case var is always empty! because record(index.row()).value("cnty_nam").isValid() is always false!!!

    I initialize the model with:

    Qt Code:
    1. m_mainmodel = new maintModel(this,db);
    2. m_mainmodel->setTable("country");
    3. m_mainmodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    4. if (m_mainmodel->select())
    5. {
    6. ui->ListView1->setModel(m_mainmodel);
    7. }
    To copy to clipboard, switch view to plain text mode 

    For sure is something very silly... but I don't know what is happening!!!

    Thanks,
    Carlos.
    Last edited by qlands; 5th July 2011 at 14:32.

Similar Threads

  1. QSqlTableModel set Integer data to NULL
    By lynnH in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2011, 17:11
  2. QTableView, QSqlTableModel - data disappears
    By msh in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2008, 11:50
  3. setting UserRole data in QSqlTableModel
    By orgads in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2008, 09:40
  4. QSqlTableModel submitAll access query
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 27th April 2007, 08:04
  5. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 17:49

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
  •  
Qt is a trademark of The Qt Company.