Results 1 to 3 of 3

Thread: Column and rows are showing empty in tableView

  1. #1
    Join Date
    Apr 2014
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Column and rows are showing empty in tableView

    Hello !!!

    I am trying to load my data base table to tableView.I have written the following piece of code.


    void UserLog:n_pushButton_7_clicked()
    {
    login conn;
    QSqlQueryModel *modal =new QSqlQueryModel;
    conn.connOpen();
    QSqlQuery* qry = new QSqlQuery(conn.db);
    qry->prepare("select * from `posdb`.items");
    if(qry->exec())
    {
    modal->setQuery(*qry);
    ui->tableView->setModel(modal);
    conn.connClose();
    }
    else
    {
    QMessageBox::critical(this,tr("error::"),qry->lastError().text());
    }

    qDebug() <<(modal->rowCount());
    }

    It is successfully loading the table.But the problem is that the table fields are emptyuser login11.jpg
    I do not guess what is the wrong with my code.I am using the following version of Qt user login12.jpg
    My database table is user login13.jpg

    I am afraid what to do.
    Help !!!
    Thanks

  2. #2
    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: Column and rows are showing empty in tableView

    You immediately close the database connection that the model is using to access your database. After this the behaviour of the model is undefined. If you want a one-off load of the table data into a widget then you should use QTableWidget and iterate over a QSqlQuery to populate it before closing the connection.

    It would be unusual to open/close the database connection in a button handler slot.

  3. #3
    Join Date
    Apr 2014
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Column and rows are showing empty in tableView

    Thanks @Chris i got your point and i got the job done

Similar Threads

  1. Qt View adds empty rows
    By RaymondMcEvilly in forum Qt Programming
    Replies: 4
    Last Post: 24th February 2013, 03:10
  2. Adding rows to Tableview
    By codeman in forum Qt Programming
    Replies: 1
    Last Post: 2nd October 2009, 10:27
  3. QSqlTableModel inserts empty rows
    By Nesbitt in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2008, 12:47
  4. QTableView showing empty fields
    By ederbs in forum Qt Programming
    Replies: 5
    Last Post: 4th October 2007, 00:30
  5. QTableView not corectly showing empty fields
    By Sergey B. in forum Qt Programming
    Replies: 4
    Last Post: 15th June 2007, 08:18

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.