Results 1 to 4 of 4

Thread: how to show my sqlite database table on mainwindow with tableview widget

  1. #1
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default how to show my sqlite database table on mainwindow with tableview widget

    Hello All,
    I am new to Qt and Sql database, now i am trying to create a sqlite database file and table.
    And now i want to display the table in my mainwindow tableview....
    Everything is ok but table is not displaying on the window...and no errors are comming...but when i clicked the submit button i got the error as shown in fig.
    here is my code in attachments..

    Thanks in advance..
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by prasad1001; 25th February 2014 at 12:56.

  2. #2
    Join Date
    Feb 2014
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: how to show my sqlite database table on mainwindow with tableview widget

    Hello prasad1001
    First of all, sorry for my english.

    you have set the database name as "hari", so try this:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    2. db.setDatabaseName("hari");
    3. ...
    4. db.open();
    5. ...
    6. QSqlQuery query(db);
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. QSqlQuery query(QSqlDatabase::database("hari", false));
    To copy to clipboard, switch view to plain text mode 
    in elsewhere.
    false makes it not open a new database even if the database named "hari" does not exist.
    Last edited by 4Tech; 25th February 2014 at 13:29.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to show my sqlite database table on mainwindow with tableview widget

    Quote Originally Posted by prasad1001 View Post
    And now i want to display the table in my mainwindow tableview....
    Everything is ok but table is not displaying on the window...and no errors are comming...but when i clicked the submit button i got the error as shown in fig.
    Your QSqlTableModel does not have a database connection to work with, see second constructor argument.
    Also the given table name is wrong (your table is not called "library data", just "library").

    Cheers,
    _

    P.S.: A Sqlite database is a single file, you don't need username or password for that.

  4. The following user says thank you to anda_skoa for this useful post:

    prasad1001 (26th February 2014)

  5. #4
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to show my sqlite database table on mainwindow with tableview widget

    Thanks for the reply sir,
    i was changed the table name and it works fine..

    Thanks..
    Last edited by prasad1001; 26th February 2014 at 06:14.

Similar Threads

  1. show object (scene) in widget in class class mainwindow
    By rimie23 in forum Qt Programming
    Replies: 8
    Last Post: 1st May 2012, 17:15
  2. QStandardItemModel to sqlite database table
    By sattu in forum Qt Programming
    Replies: 19
    Last Post: 11th March 2011, 00:01
  3. Replies: 3
    Last Post: 12th July 2010, 14:12
  4. Replies: 10
    Last Post: 29th May 2010, 19:42
  5. Replies: 4
    Last Post: 4th February 2008, 07:16

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.