PDA

View Full Version : QTableWidget to QSqltable



manmohan
11th May 2010, 10:30
Hi,
I have complete data read from a file in QTableWidget, now I want to save the QTableWidget as it is into a database and then use.

Thanks & regards
Manmohan

waynew
11th May 2010, 23:20
That is maybe not the best way to do it.

Why not try the following approach:
create a database and table
create a QSqlTableModel and QSqlRecord for the model
read the file into a QTextStream
loop through the stream load the records
insert the data from the model into the table
Create a QTableView to display the data from the model

See the model/view programming doc here: http://doc.trolltech.com/4.5/model-view-programming.html

manmohan
12th May 2010, 11:01
Header columns are not same all the time so its hard to read data and store in database table format. I wanted to create a data base which gets its no of columns by reading the file.

waynew
12th May 2010, 13:08
Then why not just read the first record in the file to see how many fields you need in the database table, then proceed to create the rest as above?