Results 1 to 2 of 2

Thread: QT SQLITE Query

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default QT SQLITE Query

    I am quite confused what is going on here and I have to be completely missing something stupid, but...

    Qt Code:
    1. mydb.open();
    2. QSqlQuery query;
    3. query.prepare("select * from inventory");
    4. query.exec();
    To copy to clipboard, switch view to plain text mode 

    A simple query to my database that works in numerous other places, just does not function at all in one of my pushbutton slots.

    Qt Code:
    1. 0x14bfed30 //Query Result
    2. " " //Query Error
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. val = ui->listView->model()->data(index).toString();
    2. mydb.open();
    3. QSqlQuery query;
    4. query.prepare("select * from inventory where item ='"+val+"'");
    5.  
    6. if(query.exec())
    7. {
    8. while(query.next())
    9. {
    10. ui->lineEdit_shelf->setText(query.value(1).toString());
    11. ui->lineEdit_container->setText(query.value(2).toString());
    12. ui->lineEdit_finished->setText(query.value(4).toString());
    13. ui->lineEdit_unfinished->setText(query.value(5).toString());
    14. ui->textEdit_notes->setText(query.value(6).toString());
    15. if(query.value(3) == 1)
    16. ui->checkBox->setChecked(true);
    17. else
    18. ui->checkBox->setChecked(false);
    19. }
    20. mydb.close();
    21. }
    22. else
    23. qDebug() << query.lastError().text();
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    Example of setup in a listView_clicked slot. But it functions perfectly well. Any kind of guidance would be greatly appreciated, as this problem popped up while I was attempting to make an update query, and it seems to be a much bigger issue.
    Last edited by andrewhopps; 14th May 2015 at 23:30.

Similar Threads

  1. QSqlQuery update query not working using SQLite
    By Cyrebo in forum Qt Programming
    Replies: 2
    Last Post: 29th March 2013, 00:33
  2. how to send sqlite query CREATE TRIGGER in qt application
    By abdul_moiz in forum Qt Programming
    Replies: 2
    Last Post: 10th June 2011, 06:07
  3. SQLITE - UPDATE query problem
    By Tomasz in forum Newbie
    Replies: 12
    Last Post: 5th September 2010, 20:27
  4. Problem with A SQLite Query
    By maveric in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2008, 11:15
  5. [QT4][SQLITE] Database and query
    By agent007se in forum Newbie
    Replies: 10
    Last Post: 12th July 2006, 22:16

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.