I'm trying to create a search box with a widget but I don't know my mistakes
-
Hi, here the code:
@void MainWindow::on_lineEdit_textChanged(const QString &arg1)
{
//Descubrir el nombre y la ubicacion del archivo csv
//QString fileName=QFileDialog::getOpenFileName(this,"Open CSV file",QDir::currentPath(),"CSV (*.csv)");
//qDebug()<<fileName;
//colocar el layout
QVBoxLayout *res_found=new QVBoxLayout(ui->result);
//abrir archivo
QFile file("/Users/alfredoluco/Documents/qtExamples/CookIT/bd.csv");
if(file.open(QIODevice::ReadOnly)){
QString data=file.readAll();
QStringList arr=data.split("\n");
for(int i=0;i<arr.length();i++){
QStringList vector=arr.at(i).split(";");
QStringList vector2=vector.at(1).split(".");
//agregar los ingredientes a el vector correspondiente
for(int j=0;j<vector2.length();j++){
ingredientes.append(vector2.at(j));
}
}
//buscar el ingrediente del buscador
if(checkBoxVector.isEmpty()){
for(int k=0;k<ingredientes.length();k++){
checkBoxVector.append(new QCheckBox(ingredientes.at(k)));
}}
for(int l=0;l<checkBoxVector.length();l++){
if(checkBoxVector.at(l)->text().contains(arg1)){
res_found->addWidget(checkBoxVector.at(l));
qDebug()<<checkBoxVector.at(l)->text();
}
}
}
else {
QVBoxLayout *res_found=new QVBoxLayout(ui->result);
QLabel *ingred_found=new QLabel();
ingred_found->setText("<p>No se ha abierto nada!</p>");
res_found->addWidget(ingred_found);
ui->result->show();
}delete res_found; //delete res_found->layout(); checkBoxVector.clear(); ingredientes.clear();
}
@
How I can change the cheboxlist in the widget?Thanks a lot!