So i am trying to connect to database from the website i own at some hosting company, here is my usage.cpp with database login info changed for obvious reasons.

And the qDebug() output i get is bellow ...

I am trying to connect to Database but it seems that wp_users table doesnt exist by qDebug() even i am sure its there. What is even weirder is that no matter what username, pass, dbname etc.. i use to connect(i can write any gibberish there) it will always tell me that connection is opened by db.open() or db.isValid()...

Please explain me why Qt doesnt give me right info that my connection succeeded and why the table that exists is reported not to be there?

This is a database i use for my wordpress website btw

Qt Code:
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. #include <QtSql>
  4.  
  5. Widget::Widget(QWidget *parent) :
  6. QWidget(parent),
  7. ui(new Ui::Widget)
  8. {
  9. ui->setupUi(this);
  10.  
  11. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  12. db.setHostName("tm4.justhost.com");
  13. db.setDatabaseName("database_name");
  14. db.setUserName("username");
  15. db.setPassword("pass");
  16.  
  17. if (!db.open()) {
  18. qDebug() << db.lastError();
  19. }
  20.  
  21. qDebug() << db.isValid();
  22.  
  23. QSqlQuery query;
  24.  
  25. query.exec("SELECT user_login, user_pass FROM wp_users");
  26.  
  27. while (query.next()) {
  28. QString user = query.value(0).toString();
  29. QString pass = query.value(1).toString();
  30. qDebug() << user << pass;
  31. }
  32.  
  33. qDebug() << query.lastError();
  34.  
  35.  
  36. }
  37.  
  38. Widget::~Widget()
  39. {
  40. delete ui;
  41. }
  42.  
  43. void Widget::changeEvent(QEvent *e)
  44. {
  45. QWidget::changeEvent(e);
  46. switch (e->type()) {
  47. case QEvent::LanguageChange:
  48. ui->retranslateUi(this);
  49. break;
  50. default:
  51. break;
  52. }
  53. }
  54.  
  55. [B]output:[/B]
  56.  
  57. true
  58. QSqlError(1, "Unable to execute statement", "no such table: wp_users")
To copy to clipboard, switch view to plain text mode