Results 1 to 6 of 6

Thread: How to Retrive data...?

  1. #1
    Join Date
    Nov 2014
    Posts
    54
    Thanks
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default How to Retrive data...?

    Hi i am trying to retrive the data from the database here is my program

    Intially i am entering the mobile no in a line edit which i have named it as "searchedit" and then i am strong the data of line edit into a string and then i am trying to reterive the data from the database by the help mobile number which is present in the string and i have written the query as beolw

    QString str1 = searchedit->text();
    searchedit->setText(str1);

    int ret;
    QSqlQuery query;
    query.exec("SELECT * FROM details WHERE mobile="(str1.data())"");

    i am storing the data in a line edit into a string and then i am trying to retrive the data from the database which matches with the data present in the string,but it is showing an error " '"SELECT * FROM details WHERE mobile="' cannot be used as a function"

    I need to retirve the details of the user by the help of their mobile numbers.

    Please help to retrive the data from the data base i am using the sqlite database and my QT version is 4.7.4

    Thanks in advance
    Rohith.G
    Last edited by gunturrohith; 24th April 2015 at 07:04.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to Retrive data...?

    Your code has incorrect C++ syntax. QSqlQuery docs contains an example how to build a query with parameters using QSqlQuery::prepare().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2014
    Posts
    54
    Thanks
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to Retrive data...?

    Sorry can you please elaborate the explanation i have not got anything which is familiar to my question in the QSqlQuery

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to Retrive data...?

    Click the second link in my post, read the docs and evaluate the code in the big gray box.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2014
    Posts
    54
    Thanks
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to Retrive data...?

    Hi thanks for your help and i have made some modifications in my code once please go through this and tell me where i am making mistake..?
    Here is my code
    Qt Code:
    1. QString str1 = searchedit->text();
    2. //searchedit->setText(str1);
    3. QString str("SELECT * FROM details WHERE mobile=");
    4.  
    5. QString finalStr = str+ str1.toAscii().data();
    6. qDebug()<<"Data in FinalStr:"<<finalStr;
    7. bool ret;
    8. QSqlQuery query;
    9. //ret=query.exec("SELECT * FROM details WHERE mobile='str1.toAscii().data()'");
    10. query.prepare("finalstr");
    11. ret=query.exec();
    12.  
    13. if(ret==true)
    14. {
    15. qDebug("comparison success");
    16. QMessageBox msgbox;
    17. msgbox.setText("<h5>Registered User</h5>");
    18. msgbox.exec();
    19. }
    20. else
    21. {
    22. QMessageBox msgbox;
    23. msgbox.setText("Not Registered");
    24. msgbox.exec();
    25. }
    26. * * * *
    To copy to clipboard, switch view to plain text mode 
    This code producing a result as Not Registered even if the data is present in the database
    Please help me
    Thanks in advance
    Rohith.G
    Last edited by anda_skoa; 26th April 2015 at 10:41. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to Retrive data...?

    Quote Originally Posted by gunturrohith View Post
    Qt Code:
    1. query.prepare("finalstr");
    To copy to clipboard, switch view to plain text mode 
    I don't think this is a valid SQL query. Do you know what is a string in c++ and how does it differ from a variable identifier?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to retrive data saved using Setdata?
    By parshant65@gmail.com in forum Qt Programming
    Replies: 5
    Last Post: 6th March 2014, 15:43
  2. I want to save and retrive a QGraphicsScene
    By c_srikanth1984 in forum Qt Programming
    Replies: 16
    Last Post: 7th January 2014, 14:19
  3. Retrive values using qt
    By jeyanthinatarajan in forum Newbie
    Replies: 1
    Last Post: 5th July 2012, 08:31
  4. Replies: 1
    Last Post: 19th March 2009, 09:20
  5. How I can retrive information abt file.
    By safknw in forum General Programming
    Replies: 3
    Last Post: 2nd December 2006, 13:35

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.