Results 1 to 3 of 3

Thread: Cannot see the header labels SQL

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Cannot see the header labels SQL

    Dear Friends

    I am trying to generate a table with the code below. But I cannot see the header labels in the view. Only a blank page is coming. Please give me some suggestion. Thanks sujan
    Qt Code:
    1. model->setTable("student");
    2. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    3. model->select();
    4. model->setHeaderData(0, Qt::Horizontal, tr("studentID"));
    5. model->setHeaderData(1, Qt::Horizontal, tr("Name"));
    6. model->setHeaderData(2, Qt::Horizontal, tr("FirstName"));
    7. model->database().transaction();
    8. qDebug() << model->database().commit();
    9. model->submitAll();
    10. QTableView *view = new QTableView;
    11. view->setModel(model);
    12. view->show()
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 26th June 2011 at 23:30. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Cannot see the header labels SQL

    Where did you set up the database connection? And for a QSqlQueryModel you have to perform a query. If you want to set a table use QSqlTableModel.

  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: Cannot see the header labels SQL

    Your sample code won't compile for the reason pointed out by Lykurg. Once that is corrected the code works fine for me.

    You should get into the habit of checking return values and, when they indicate errors, QSqlDatabase::lastError() or QSqlQueryModel::lastError().
    QSqlTableModel::select() returns a true/false indication you are ignoring.

Similar Threads

  1. QTableWidget custom header labels
    By migel in forum Newbie
    Replies: 1
    Last Post: 1st June 2011, 09:20
  2. QStandardItem's header item and header label
    By feverzsj in forum Newbie
    Replies: 1
    Last Post: 14th January 2010, 19:57
  3. Setting two horizontal header labels for QTablewidget
    By arunvv in forum Qt Programming
    Replies: 2
    Last Post: 20th August 2009, 17:58
  4. How to customize horizontal header (diagonal header view)
    By vairamuthu.g in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 15:59
  5. Replies: 1
    Last Post: 23rd August 2006, 18:02

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.