PDA

View Full Version : How to get textEdit data to work with split regex



editheraven
29th March 2017, 20:45
I have a small application that uses sqlite3 to add recipes and then search them by index, name and ingredients.

The way I've done the ingredients part is


ingredients = this->ui->textEdit->toPlainText();

And then you could query them with


ingredients = ui->lineEdit_3-> text() + '%';
ingredients = '%' + ingredients ;

QRegExp rx("(\\ |\\,|\\.|\\:|\\t)"); //RegEx for ' ' or ',' or '.' or ':' or '\t'
QStringList ingredients_splt = ingredients.split(rx);

this->ui->label->setText(ingredients);

QSqlQuery query;

if (MainWindow::select_ingredients==1)
{
query.prepare("SELECT ID, name, ingredients FROM recipes WHERE ingredients LIKE (:ingredients)");
.
.
.
query.bindValue(":ID",ID);
query.bindValue(":name",name);
query.bindValue(":ingredients",ingredients_splt);
query.exec();
model->setQuery(query);
}

But the split won't work. It just skips any regex sepparators.

I have added my whole project to this post.

le : I still have some debug coding in my program. Just ignore it.