Results 1 to 5 of 5

Thread: qt read csv write sqlite

  1. #1
    Join Date
    May 2015
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Angry qt read csv write sqlite

    Hi all,

    I am trying to load data from a csv file into a QTableView and I want to insert this data into a SQLite database, how does one transfer data that is in a QTableView into the SQLite database. I got the code of loading the csv file into the QTableView from this link: http://qtsimplify.blogspot.com/2013/...-easy-way.html .I am only able to find solutions whereby the initial query was instantiated from a database and so updating of certain fields is permitted but this to load all values that are present in the current QTableView into the SQLite database, let us say a table called MyCSV.

    Thanking you in advance. It would help providing code with the explanation if possible please.

  2. #2
    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: qt read csv write sqlite

    You just run QSqlQuery INSERT queries on the database as you iterate over the data row by row.

    Cheers,
    _

  3. #3
    Join Date
    May 2015
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qt read csv write sqlite

    Hi anda_skoa,

    Is that the only and best method suggested by Qt? In visual studio and lazarus, you are able to save the datagridview in one go. I was hoping that Qt would offer the same sort of saving feature. If not, then I guess I will just need to try it using your method.

    Thanking you in advance.

  4. #4
    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: qt read csv write sqlite

    If you back the view with a QSql based model than you can add rows there.

    I personally would have done the import first and then the visualization, keeping the data handling independent of any UI, nicely unit testable, etc.

    Cheers,
    _

  5. #5
    Join Date
    May 2015
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Red face Re: qt read csv write sqlite

    Hi anda_skoa,

    The reason I have opted to go wih the viewer before applying the updates as it gives the user a graphical view to make sure the csv file is in the correct format and I also only wish to update a few records from the actual table rather than the whole table. So I need to allow for the user to specify the fields of the table which the uploaded csv file will update. I however have found an example of what you are saying about diirectly importing it into SQLite prior to the user seeing it but if the file is in the incorrect format, the user will not be able to fix it unless they manually do the work through a text editor.

    http://dustri.org/b/import-cvs-to-sqlite-with-qt.html

    I can only think of applying the QTableView to a QSqlTableModel but how would one go about applying that?

    I think I have the write project group - they seem to be on my wave-length - http://sqlitebrowser.org/ - all designed with Qt.
    Last edited by chris.kzn; 27th May 2015 at 13:56.

Similar Threads

  1. Replies: 8
    Last Post: 9th March 2014, 13:55
  2. DVD write & read
    By mekalapandiyan@gmail.com in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2013, 07:37
  3. Replies: 2
    Last Post: 2nd November 2010, 05:15
  4. sqlite write security
    By lesat in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2010, 05:05
  5. XML -read-write
    By hgedek in forum Qt Programming
    Replies: 2
    Last Post: 3rd September 2007, 18:10

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.