使用前 槽函数声明void IQCPartNoChoose::selectFun(std::string dbName, const QString arg1,std::vector<std::string> &vec_rowRes
实现void IQCPartNoChoose::on_lineEdit_textChanged(const QString &arg1)
{
item_model->clear();
std::vector<std::string> vec_RowRes1;//接收从db查询出的料号
// std::string dbName = PLI_DB;
PLI_DB_path = "./Golden\\DB"; //2021/8/23
//QString sql = "Select Model from Model where model glob '"+arg1+"*'";
//std::string selectSql = sql.toStdString();
//selectDBFun(PLI_DB_path,selectSql,vec_RowRes1);、
selectFun(PLI_DB_path,arg1,vec_RowRes1);
//如果未输入搜索字符 则显示所有的料号
if(arg1==""){
setTable(vec_RowRes);
}else{
setTable(vec_RowRes1);
}
}
//搜索方法 void IQCPartNoChoose::selectFun(std::string dbName, const QString arg1,std::vector<std::string> &vec_rowRes){
QDir snpath(QString::fromStdString(dbName));
QFileInfoList fileInfoList = snpath.entryInfoList();
foreach(QFileInfo fileInfo,fileInfoList){
if(fileInfo.suffix()!="db"){//只需要db文件
continue;
}
int position = arg1.size();//通过搜索框输入的字符 找所有开头一样的文件遍历出来
QString begin = fileInfo.baseName().mid(0,position);
if(begin.toUpper()==arg1.toUpper()){
vec_rowRes.push_back(fileInfo.baseName().toStdString());
}
}
//将拿到的数据进行排序 按照字母 长短
if(vec_rowRes.size() > 0 )
{
sort(vec_rowRes.begin(),vec_rowRes.end());
vec_rowRes.erase(unique(vec_rowRes.begin(),vec_rowRes.end()),vec_rowRes.end());
} }
使用后:会根据字母,数字排序