PDA

View Full Version : read sqlite to array



vanduongbk
23rd September 2013, 08:07
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

anda_skoa
23rd September 2013, 08:59
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,
_

vanduongbk
1st October 2013, 10:40
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

anda_skoa
1st October 2013, 14:08
Lets assume you take the first approach

You get the model


QAbstractItemModel *model = tableView->model();


To get the number of rows use QAbstractItemModel::rowCount()


const int rowCount = model->rowCount();


Now you loop over all rows.
For each row you either loop over the columns or address them specifically


QModelIndex index = model->index(currentRow, 0); // first column;


You get the displayed text of a cell from the QModelIndex


QString text = index.data(Qt::DisplayRole).toString();


Cheers,
_