PDA

View Full Version : how to store data in a tablewidget and in a list througout the application



akash
7th March 2012, 07:45
Hi,
I want to store some information related to a student in a table, so i m using tablewidget to display that data.
For this created a
1. mainwindow.ui (studentdatabase button, some more buttons)
2. studentdatabase.ui (tablewidget, addnewstudent button).
clicking addnewstudent button opnes a dialog having name, rollno, year and semeter lineedit fields. Entering all the details and OK button closes the dialog and inserts new row in tablewidget and displays the same data.
3. but when i close studentdatabase.ui and reopens the same, tablewidget with no data/row is displayed. student data is lost.

I tried:
I tried using a QStringList in a class and storing the same data in it, but as soon as i reopen the ui List is also empty.

Please let me know how to solve this issue, so that if i close studentdatabase.ui and reopens the same, student information is always there and new student info can be added.
Please let me where should i declare the class object and list variable to store the data of N students.

Thanks in advance for helping me.

AlexSudnik
7th March 2012, 07:57
What do you mean "when i close studentdatabase.ui and reopens the same" ? Do you want to shut down your application and be able to restore previous session's data ?

akash
7th March 2012, 08:03
nope...studentdabase.ui is a child window of mainwindow.ui, i m closing studentdatabase.ui and reopening the same without shuting down my entire application i.e manwindow.ui

ChrisW67
7th March 2012, 08:04
Please let me know how to solve this issue, so that if i close studentdatabase.ui and reopens the same, student information is always there and new student info can be added.
Start by not expecting Qt and C++ to magically save and restore data.

Please let me where should i declare the class object and list variable to store the data of N students.
Whatever you use to hold the data that you want to persist when the UI does not exist it must be outside the UI class. Given that the data is tabular and you are using a table-like display you should look at using a QStandardItemModel to hold the data in-memory, and QTableView (i.e. replace the QTableWidget) to display it. You could even look at a custom QAbstractTableModel subclass.

Nothing here addresses making the student data persist when the program is no longer running.

akash
7th March 2012, 08:33
thanks for this information, i will try to make it through and update,.....
thanks,