weevle123
3rd May 2010, 04:43
Hi everyone,
I'm new to Qt and would really appreciate help on a problem I have been having. I am doing a simple database program in C++ and I want to search through the products in one QSqlTableModel (modelInventory) for matches to a string and transfer the matching products to another QSqlTableModel (modelSearchResult).
for (int i_count=0; i_count < (modelInventory->rowCount()); i_count++)
{
//The name of the current product being checked in the inventory model
QString tempProdName = modelInventory->record(i_count).value(1).toString();
QSqlRecord setterRecord = modelSearchResult->record(); //A record to set the search
//result model with
//If there is a substring match between the current product name and the search
//string (both ways), transfer all the information of that inventory record
//and put it into the temporary search result record "setRecord". Also,
//store the current "i_count" value into the eighth field of the search
//result record to remember the index of the record
if ( ( tempProdName.indexOf(searchString,0,Qt::CaseInsens itive) != -1 )
|| ( searchString.indexOf(tempProdName,0,Qt::CaseInsens itive) != -1) )
{
//Transfer over all the field information as well as the current index
//being searched
setterRecord.setValue(0, modelInventory->record(i_count).value(0));
setterRecord.setValue(1, modelInventory->record(i_count).value(1));
setterRecord.setValue(2, modelInventory->record(i_count).value(2));
setterRecord.setValue(3, modelInventory->record(i_count).value(3));
setterRecord.setValue(4, modelInventory->record(i_count).value(4));
setterRecord.setValue(5, modelInventory->record(i_count).value(5));
setterRecord.setValue(6, modelInventory->record(i_count).value(6));
setterRecord.setValue(7, modelInventory->record(i_count).value(7));
setterRecord.setValue(8, QVariant(i_count)); //Store the index of the record in the
//inventory model in the search result
//model
//Append the new search match into the search result model
modelSearchResult->insertRecord(-1, setterRecord);
} //END if ( ( tempProdName.indexOf(searchString,0,Qt::CaseInsens itive) != -1 )
// || ( searchString.indexOf(tempProdName,0,Qt::CaseInsens itive) != -1) )
} //END for (int i_count=0; i_count< (modelInventory->rowCount()); i_count++)
When I comment out the for loop and replace it with: int i_count = 2; it will be able to parse the third (2+ 1) record in the inventory model. So is there something wrong with my for loop? I know that the rowCount() return the right number of rows.
I would really appreciate if you guys could help me, thanks!
I'm new to Qt and would really appreciate help on a problem I have been having. I am doing a simple database program in C++ and I want to search through the products in one QSqlTableModel (modelInventory) for matches to a string and transfer the matching products to another QSqlTableModel (modelSearchResult).
for (int i_count=0; i_count < (modelInventory->rowCount()); i_count++)
{
//The name of the current product being checked in the inventory model
QString tempProdName = modelInventory->record(i_count).value(1).toString();
QSqlRecord setterRecord = modelSearchResult->record(); //A record to set the search
//result model with
//If there is a substring match between the current product name and the search
//string (both ways), transfer all the information of that inventory record
//and put it into the temporary search result record "setRecord". Also,
//store the current "i_count" value into the eighth field of the search
//result record to remember the index of the record
if ( ( tempProdName.indexOf(searchString,0,Qt::CaseInsens itive) != -1 )
|| ( searchString.indexOf(tempProdName,0,Qt::CaseInsens itive) != -1) )
{
//Transfer over all the field information as well as the current index
//being searched
setterRecord.setValue(0, modelInventory->record(i_count).value(0));
setterRecord.setValue(1, modelInventory->record(i_count).value(1));
setterRecord.setValue(2, modelInventory->record(i_count).value(2));
setterRecord.setValue(3, modelInventory->record(i_count).value(3));
setterRecord.setValue(4, modelInventory->record(i_count).value(4));
setterRecord.setValue(5, modelInventory->record(i_count).value(5));
setterRecord.setValue(6, modelInventory->record(i_count).value(6));
setterRecord.setValue(7, modelInventory->record(i_count).value(7));
setterRecord.setValue(8, QVariant(i_count)); //Store the index of the record in the
//inventory model in the search result
//model
//Append the new search match into the search result model
modelSearchResult->insertRecord(-1, setterRecord);
} //END if ( ( tempProdName.indexOf(searchString,0,Qt::CaseInsens itive) != -1 )
// || ( searchString.indexOf(tempProdName,0,Qt::CaseInsens itive) != -1) )
} //END for (int i_count=0; i_count< (modelInventory->rowCount()); i_count++)
When I comment out the for loop and replace it with: int i_count = 2; it will be able to parse the third (2+ 1) record in the inventory model. So is there something wrong with my for loop? I know that the rowCount() return the right number of rows.
I would really appreciate if you guys could help me, thanks!