PDA

View Full Version : How send result query database to List<QString>



bartes19
9th January 2016, 16:42
How send result query database to List<QString> ???

anda_skoa
9th January 2016, 17:11
You will have to add more information on what you are trying to do.

What kind of values are you querying for? Does it query for one or more values per row?

Cheers,
_

bartes19
9th January 2016, 21:59
I would like send value from two column table Qtableview (value int and varchar) to Qcombobox

query: select kod_lekarstwa, nazwa from lekarstwo;


I think about such loop:

for (list<QString>::iterator it=diseases.begin(); it != diseases.end(); ++it)
{
ui->diseasecomboBox->addItem(*it);
}

anda_skoa
10th January 2016, 01:38
You can use QString::number() to convert the int value to a string and then use the + operator to concatenate with the second part.
That string can then easily be appended to a QStringList (which is a QList<QString>)

Cheers,
_

bartes19
10th January 2016, 12:49
on start we try to do on the one column , only String values
select nazwa from lekarstwo;

it works, but I don't know how appended result query to QList


QList<QString> list;
list << "item1" << "item2" << "item3";

QString s;
foreach( s, list )
{
qDebug() << s;
ui->comboBoxmedicine->addItem(s);
}

anda_skoa
10th January 2016, 13:35
I am afraid I don't understand.
Your code already adds strings to the list, i.e. you already know how the << operator works.

Cheers,
_

bartes19
10th January 2016, 16:28
Something like that?

list << query.exec("select kod_lekarstwa, nazwa from lekarstwo;");

anda_skoa
10th January 2016, 17:33
exec() returns a bool.

You want to loop over the results. See the example in the documentation for QSqlQuery.

Cheers,
_