PDA

View Full Version : Quick Question on QSqlQuerry



locus
13th March 2007, 14:30
I have linked my QSqlQuerry model to a view that is supposed to display the result of the following querry


model->setQuery("SELECT * FROM user_info WHERE user_fname = 'lineEdit->text()' ");

I am trying to implement a simple search where a user enters a name (in lineEdit) and gets the record corresponding to that name.

the code i have there does not work,as i think lineEdit->text() is being seen as a literal, and thats waht the querry searches for, instead of what the user entered(the lineEdit's value).

How do i get the value of the lineEdit into the querry for it to give me the results i want.

Thanks for your attention.

Lykurg
13th March 2007, 14:53
model->setQuery("SELECT * FROM user_info WHERE user_fname = 'lineEdit->text()' ");

Hi,
it must be:
model->setQuery("SELECT * FROM user_info WHERE user_fname = '"+lineEdit->text()+"' ");

but also have a look on setFilter:
model->setFilter("user_fname LIKE '"+lineEdit->text()+"%'");

Lykurg

P.s.: And check lineEdit->text() for ' to escape!