Results 1 to 4 of 4

Thread: Using tableview with CSV

  1. #1
    Join Date
    Jul 2013
    Posts
    27
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Using tableview with CSV

    Hello friends,
    I am using table view to show some data which will be read from a csv file. But i have to access the csv file through a translator as the contents are going to be changed dynamically, so storage, sync and retrieval should be proper. I have a translator implemented, which uses a hash function. My dilemma is how to dynamically set row count and column count. As i viewed the model view documentation, there are 2 functions and the return value of it decides the row count and column count. I am posting the link for the doc and the function name below :-

    http://qt-project.org/doc/qt-4.8/modelview.html
    int MyModel::rowCount(const QModelIndex & /*parent*/) const
    {
    return 2;
    }

    int MyModel::columnCount(const QModelIndex & /*parent*/) const
    {
    return 3;
    }

    As one can see above, if it returns 2 rows, then 2 rows are displayed in the model. How can i do this dynamically with a csv file?

  2. #2
    Join Date
    Aug 2012
    Location
    Loughborough, UK
    Posts
    29
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Using tableview with CSV

    sort've implies that you need to read the csv file, and store the row count. Each time row count is called check if the csv has been updated somehow and re-cache the row count.

  3. The following user says thank you to rockdemon for this useful post:

    akshaysulakhe (19th July 2013)

  4. #3
    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: Using tableview with CSV

    The column count is known once you read the first record of the CSV file.
    You can read the entire CSV file to determine a total row count. For a small file this is probably easiest.

    Alternatively, implement a lazy fetching mechanism where you read rows in sets of up to n rows and return rowCount() of the number actually read to date. On open/reset the model reads up to n rows and rowCount() returns the number read. Implement canFetchMore() and fetchMore() to allow views to see the entire table if required. QSqlTableModel uses this approach with n == 256.

  5. The following user says thank you to ChrisW67 for this useful post:

    akshaysulakhe (19th July 2013)

  6. #4
    Join Date
    Jul 2013
    Posts
    27
    Thanks
    11
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using tableview with CSV

    Thank You guys, the CSV file is not that big. This will work. Ty :-)

Similar Threads

  1. tableview with doubles
    By Arend in forum Newbie
    Replies: 2
    Last Post: 26th November 2012, 06:43
  2. tableview
    By GuL in forum Newbie
    Replies: 1
    Last Post: 26th August 2008, 17:18
  3. help in tableview
    By bala in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 15:46
  4. getting data from tableView
    By mkarakaplan in forum Newbie
    Replies: 1
    Last Post: 7th November 2007, 09:51
  5. getting current Id from tableView
    By mkarakaplan in forum Newbie
    Replies: 3
    Last Post: 7th October 2007, 22:14

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.