Results 1 to 6 of 6

Thread: QSqlQuery problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 1 Time in 1 Post

    Default Re: QSqlQuery problem

    I don't understand what you mean with assign en contents.
    Can you give me a little example?.
    Thank in advance.

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

    Default Re: QSqlQuery problem

    Quote Originally Posted by dragon View Post
    I don't understand what you mean with assign en contents.
    Can you give me a little example?
    Here you assign to the variable called name:
    Qt Code:
    1. name = (query.value(0).toString());
    To copy to clipboard, switch view to plain text mode 

    If you want to make a search you need something like this:
    Qt Code:
    1. while ( query.next() )
    2. if(name == query.value(0).toString()){
    3. leFirst->setText( name );
    4. break;
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 
    Do you see the difference?

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 1 Time in 1 Post

    Default Re: QSqlQuery problem

    Yes i see the differents.
    It works fine.
    Thak you for your time and answer.

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

    Default Re: QSqlQuery problem

    Of course it would be simpler to do it this way:

    Qt Code:
    1. void MainWindow::search() {
    2. searchDialog dlg(this);
    3. if( dlg.exec() == QDialog::Accepted) {
    4. QSqlQuery query;
    5. query.prepare("SELECT firstname FROM person WHERE firstname==:name");
    6. query.bindValue(":name", dlg.nameComboBox->currentText());
    7. if(query.exec() && query.hasNext())
    8. leFirst->setText( name);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 13:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 15:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22:36
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.