Results 1 to 10 of 10

Thread: Why does the last row remain in QTableView until the page is reloaded ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Why does the last row remain in QTableView until the page is reloaded ?

    Sure, no worries. One more thing:

    Qt Code:
    1. QSqlQueryModel *model = new QSqlQueryModel(ui->tableView_staffLog);
    To copy to clipboard, switch view to plain text mode 

    This also needs to be done only once, when you create the class that contains this code. You do not need to create a new model each time you do a query (eg. on each data reload). Create the model one time, set it on the table, and remember the pointer as a member variable of your class (or retrieve it from the table in the data reload method via QAbstractItemView::model()). The only things you need to do in your reload data method are:

    - prepare the query (maybe; if it is the same query every time, then make it a member variable too and prepare it once)
    - exec() the query
    - if exec() returns true, set the query on the model, otherwise clear() the model.

    Everything else - setting the header data, setting the model on the view, etc. can be done once in the constructor.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    zed220 (12th August 2017)

Similar Threads

  1. Replies: 3
    Last Post: 20th February 2018, 14:55
  2. qtableview multiply page support
    By tdm in forum Newbie
    Replies: 1
    Last Post: 1st March 2017, 04:41
  3. Symbols remain after running strip
    By ScottBell in forum Qt Tools
    Replies: 0
    Last Post: 7th November 2011, 03:30
  4. Compiling QT programs in Visual C++ 2008 by including batch files, reloaded projects
    By Meek the Geek in forum Installation and Deployment
    Replies: 6
    Last Post: 12th July 2010, 20:11
  5. QMenu: remain visible while mouseOver
    By vonCZ in forum Newbie
    Replies: 10
    Last Post: 25th October 2007, 16:54

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