Results 1 to 5 of 5

Thread: how to store data in a tablewidget and in a list througout the application

  1. #1
    Join Date
    Aug 2011
    Location
    Pune, India
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default how to store data in a tablewidget and in a list througout the application

    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.

  2. #2
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to store data in a tablewidget and in a list througout the application

    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 ?

  3. #3
    Join Date
    Aug 2011
    Location
    Pune, India
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to store data in a tablewidget and in a list througout the application

    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

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to store data in a tablewidget and in a list througout the application

    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.

  5. #5
    Join Date
    Aug 2011
    Location
    Pune, India
    Posts
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to store data in a tablewidget and in a list througout the application

    thanks for this information, i will try to make it through and update,.....
    thanks,

Similar Threads

  1. How to display data from tablewidget using fiter mechanism
    By lekhrajdeshmukh in forum Qt Programming
    Replies: 8
    Last Post: 13th December 2011, 04:34
  2. Need ideas on how to store data in SQL-Database
    By homerun4711 in forum Newbie
    Replies: 3
    Last Post: 5th January 2011, 23:10
  3. QList & QPointer to store object list
    By maddog_fr in forum Qt Programming
    Replies: 12
    Last Post: 8th August 2009, 20:39
  4. Replies: 5
    Last Post: 8th April 2008, 23:10
  5. How to store/get pointer on QTreeWidgetItem data?
    By Teerayoot in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2007, 22:26

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.