Results 1 to 4 of 4

Thread: read sqlite to array

  1. #1
    Join Date
    Jan 2013
    Posts
    44
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default read sqlite to array

    hello everyones
    i have a question which need help,
    i have creat a database in qsqlite with 4 column and 100 rows,
    after i use qtableview to display this database
    how i can read all column of qtableview to array with 100 rows element for array
    or how i can read all items in sqlite to array above
    thank

  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: read sqlite to array

    From the table view you can get the data using its model, accessible through the model() method.
    From the database you can use QSqlQuery

    Cheers,
    _

  3. #3
    Join Date
    Jan 2013
    Posts
    44
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: read sqlite to array

    hi you
    i am a newbie ,therefore i still dont know, you can demo it
    can you help me to get all items from qtableview(4 rows ,4 columns) to string
    thank

  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: read sqlite to array

    Lets assume you take the first approach

    You get the model
    Qt Code:
    1. QAbstractItemModel *model = tableView->model();
    To copy to clipboard, switch view to plain text mode 

    To get the number of rows use QAbstractItemModel::rowCount()
    Qt Code:
    1. const int rowCount = model->rowCount();
    To copy to clipboard, switch view to plain text mode 

    Now you loop over all rows.
    For each row you either loop over the columns or address them specifically
    Qt Code:
    1. QModelIndex index = model->index(currentRow, 0); // first column;
    To copy to clipboard, switch view to plain text mode 

    You get the displayed text of a cell from the QModelIndex
    Qt Code:
    1. QString text = index.data(Qt::DisplayRole).toString();
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    vanduongbk (2nd October 2013)

Similar Threads

  1. Replies: 2
    Last Post: 26th March 2011, 04:29
  2. read ini file content and save into array
    By cooper in forum Newbie
    Replies: 8
    Last Post: 14th March 2011, 21:33
  3. read a .txt file and store it in a double array
    By fatecasino in forum Newbie
    Replies: 5
    Last Post: 3rd December 2010, 20:13
  4. read from file into array
    By obad in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2010, 08:26
  5. sqlite read lock.
    By gilgm in forum Qt Programming
    Replies: 6
    Last Post: 18th June 2010, 05:58

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.