如下所示
void CSelectSeimsicDialog::showFindfilename()
{QString t_filter=ui.findData_lineEdit->text();
QList<QListWidgetItem *> t_list;
t_list= ui.SeimsicData_listWidget->findItems(t_filter,Qt::MatchStartsWith);
//若str == ""findItems函数能返回全部项
QStringList t_filterstrList;
if(!t_list.isEmpty())
{
for(int i=0;i<t_list.size();i++)
{
t_filterstrList<<t_list.at(i)->text();
}
ui.SeimsicData_listWidget->clear();
for(int i =0;i<t_filterstrList.size();i++)
{
ui.SeimsicData_listWidget->addItem(t_filterstrList.at(i));
}
}
else
{
QMessageBox::warning(this, tr("error"),
tr("Not Exist,Please Find Again!"));
ui.findData_lineEdit->clear();
return;
}
可以初始化列表
QList<QListWidgetItem *> t_listfilename;
for (int i=0;i<ui.SeimsicData_listWidget->count();i++)
{
t_listfilename.append(ui.SeimsicData_listWidget->item(i));
}
for(int i=0;i<t_listfilename.size();i++)
{
m_vecallfilename.push_back(t_listfilename[i]->text());
}
const vector<QString>m_constfielname=m_vecallfilename;
initdlg(m_vecallfilename);
另外的查找匹配方法:
//vector<QString>::iterator itemfilename;
//QStringList t_filterstrList;
//QString t_filter=ui.findData_lineEdit->text();
// for ( itemfilename=t_vecallfilename.begin();itemfilename!=t_vecallfilename.end();itemfilename++)
// {
// if( (*itemfilename).contains(t_filter))
// {
// t_filterstrList<<((*itemfilename));
// }
只比较QString的方法
QString t_filter=ui.findData_lineEdit->text();
ui.SeimsicData_listWidget->clear();
for (int i = 0; i < m_allName.size(); i++)
{
if(m_allName[i].contains(t_filter))
{
ui.SeimsicData_listWidget->addItem(m_allName[i]);
}
}