Results 1 to 2 of 2

Thread: Weird Sql connection issue, db.open() tells me connection is there even it really isn

  1. #1
    Join Date
    Mar 2010
    Posts
    8
    Thanks
    7
    Qt products
    Qt4

    Default Weird Sql connection issue, db.open() tells me connection is there even it really isn

    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 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Weird Sql connection issue, db.open() tells me connection is there even it really

    You are sure it is a SQLIte database? Isn't it a MySQL?

    Why it return the is because qt creates a new database file in the directory of your executable named "database_name". This is the default behavior for SQLite databases. They also don't accept host, username and password.

Similar Threads

  1. Connection to dbf
    By codeman in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2010, 20:02
  2. connection is not open
    By emental86 in forum Qt Programming
    Replies: 3
    Last Post: 1st December 2008, 22:04
  3. connection
    By mickey in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2006, 20:25
  4. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 19:06
  5. Replies: 1
    Last Post: 13th February 2006, 10:02

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.