qt使用lineedit实现简单的搜索方法

使用前

槽函数声明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());
    }
}

使用后:会根据字母,数字排序

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值