Results 1 to 5 of 5

Thread: Connection With database

  1. #1
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Connection With database

    Hi every body ,
    I am using Qt4.4.3 , VS2005 . I wrote a code to connect to database . The is as follows .

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setDatabaseName("appolice");
    3. db.setHostName("localhost");
    4. db.setUserName("root");
    5. db.setPassword("root");
    6. db.setPort(3307);
    7. if(!db.open())
    8. QMessageBox::information(this,"","Database Connection Failed");
    To copy to clipboard, switch view to plain text mode 

    I create one QT GUI app and used this code to connect to database , I am able to connect . But I created one more new Qt GUI app where I used same code to connect to data base but it is not able to connect . I didn't get why it is connecting in one application and why it is failed to connect in another application.
    Please help me to make connect .

    Regards,
    Sudheer.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Connection With database

    On the same machine?

  3. #3
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Connection With database

    Yes on the same machine and same environment.

    Regards,
    Sudheer .

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Connection With database

    And what's the console output?
    Or instead "Database connection failed" display
    Qt Code:
    1. db.lastError().text()
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #5
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Connection With database

    Hi , the error message is as follows
    Qt Code:
    1. Can't connect to MySQL server on 'localhost'(1002)QMYSQL:Unable to connect
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 09:30
  2. Database connection
    By poporacer in forum Newbie
    Replies: 7
    Last Post: 7th September 2010, 08:49
  3. connection to sqlite database using qt4
    By elimelick in forum Newbie
    Replies: 0
    Last Post: 25th July 2010, 15:53
  4. database connection
    By peace_comp in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2008, 13:16
  5. Oracle Database Connection
    By ToddAtWSU in forum Qt Programming
    Replies: 6
    Last Post: 20th December 2007, 16:18

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.