Results 1 to 2 of 2

Thread: Quick Question on QSqlQuerry

  1. #1
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Quick Question on QSqlQuerry

    I have linked my QSqlQuerry model to a view that is supposed to display the result of the following querry

    Qt Code:
    1. model->setQuery("SELECT * FROM user_info WHERE user_fname = 'lineEdit->text()' ");
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Quick Question on QSqlQuerry

    Quote Originally Posted by locus View Post
    Qt Code:
    1. model->setQuery("SELECT * FROM user_info WHERE user_fname = 'lineEdit->text()' ");
    To copy to clipboard, switch view to plain text mode 
    Hi,
    it must be:
    Qt Code:
    1. model->setQuery("SELECT * FROM user_info WHERE user_fname = '"+lineEdit->text()+"' ");
    To copy to clipboard, switch view to plain text mode 

    but also have a look on setFilter:
    Qt Code:
    1. model->setFilter("user_fname LIKE '"+lineEdit->text()+"%'");
    To copy to clipboard, switch view to plain text mode 

    Lykurg

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

  3. The following user says thank you to Lykurg for this useful post:

    locus (13th March 2007)

Similar Threads

  1. Quick spacing question
    By bruccutler in forum Newbie
    Replies: 4
    Last Post: 8th March 2007, 20:46
  2. Quick question regarding abstract classes and DLLs
    By durbrak in forum Qt Programming
    Replies: 1
    Last Post: 8th February 2007, 21:32
  3. quick question on model/view programming
    By locus in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2007, 10:04
  4. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34
  5. QVector QVarLengthArray speed question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2007, 09:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.