PDA

View Full Version : Matching Data from QStringList



prophet0
30th March 2012, 20:56
I have an SQL Query that retrieved data into a QStringList (data1,data2) when i import the results from that value position ie: data1 << sqlquery.value(3).toString(); and data2 << sqlquery.value(6).toString();

data1 contains:
36
50

data2 contains:
f5d7e.avi
c2d96.png

now assuming that the first string in the list would be 36 for data1 and f5d7e.avi for data2

now if i want to say



QStringList data1,data2;
data1 << "36" << "50";
data2 << "f5d7e.avi" << "c2d96.png";

int data1Size = data1.size();
int data2Size = data2.size();
QString data1String, data2String;

for(int i = 0; i < data1Size; i++){
data1String = data1.at(i);
for(int f = 0; f < data2Size; f++){
data2String = data2.at(f);
}
}
qDebug() << "Data1: " +data1String +" Data2: " +data2String;


now how do i get the correct information on 1 line like

Data1: 36 Data2: f5d7e.avi
Data1: 50 Data2: c2d96.png

Thanks for your assistance...

Lykurg
30th March 2012, 22:14
If that is the only information you want to get out of the database then use the SELECT statement (see for concat function). And the right loop would be

QStringList result;
for(int i = 0; i < data1Size; i++){ // assuming data1Size == data2Size
result << "Data1:" << data1.at(i) << " Data2:" << data2.at(i);
}
qWarning() << result;
qWarning() << result.join("; ");

prophet0
30th March 2012, 23:02
now how would i be able to do something like this

data1 contains
36
50

data2 contains
111.avi
1111.png
222.avi
2222.png

now from my sql query 111.avi & 1111.png belong to 36 and 222.avi & 2222.png belong to 50

how would i accomplish such task?

ChrisW67
31st March 2012, 07:52
Define the rules that connects an entry in the first list with an entry, or entries, in the second. If you cannot, and I suspect this to be the case, then you need to look at the way you are getting the data out of the database. RDBMS systems are designed to do related queries, why not use it.