Results 1 to 1 of 1

Thread: {solved}Trying to test a qtsqlite database, experiencing strange issues

  1. #1
    Join Date
    Sep 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default {solved}Trying to test a qtsqlite database, experiencing strange issues

    First of here is my code:
    Qt Code:
    1. #include "dbmanager.h"
    2. #include<qdebug.h>
    3.  
    4.  
    5. dbManager::dbManager()
    6. {
    7. db = QSqlDatabase::addDatabase("QSQLITE");
    8. db.setDatabaseName("Decoders.db");
    9.  
    10. if(!db.open())
    11. qDebug() << "Not connected to DB.";
    12. else if(db.open())
    13. qDebug() << "Connected to DB.";
    14. }
    15. void dbManager::nametest()
    16. {
    17.  
    18. QSqlQuery query;
    19.  
    20. query.prepare("SELECT name FROM Restaurant");
    21. int idName = query.record().indexOf("name");
    22. if(query.exec())
    23. {
    24. while(query.next())
    25. {
    26. QString name =query.value(idName).toString();
    27. qDebug() << name;
    28. }
    29. }
    30. else
    31. {
    32. qDebug() << query.lastError();
    33. }
    34.  
    35. }
    To copy to clipboard, switch view to plain text mode 

    The problem: I made a table called restaurant is sqlite studio, I am testing to just print the first couple names from the database to the console.
    I have done this exact type of thing in a previous project with zero problems yet here it doesn't work at all. It just outputs this: "QSqlError("", "Unable to fetch row", "No query")" whenever I run the test method I have above
    I have triple checked that I my prepare statement has the correct column names and everything. Any help would be great.

    Edit: changed this

    db.setDatabaseName("../Database/Decoders.sqlite");

    Having the database file with the source code was the issue, having it in a different directory fixed the problem
    Last edited by nsidaris; 19th September 2016 at 22:25. Reason: solved problem

Similar Threads

  1. Issues on Qt test framework
    By Noren in forum Newbie
    Replies: 1
    Last Post: 19th February 2016, 17:59
  2. qtsqlite build problem
    By cdarwin in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2013, 23:00
  3. Strange issues with QSqlQuery
    By SIFE in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2011, 11:51
  4. Strange Database Driver Error
    By cevou in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2010, 23:38
  5. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 18:50

Tags for this Thread

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.