Results 1 to 3 of 3

Thread: QtSQL and databse

  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QtSQL and databse

    how can i use a settings class to use DB for my entire application



    Qt Code:
    1. db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setHostName("localhost");
    3. db.setDatabaseName("MYDATABASE");
    4. db.setUserName("root");
    5. db.setPassword("MYPASS");
    To copy to clipboard, switch view to plain text mode 

    i need to use if(db.open) across my application how would i be able to access it

    could you please use examples thanks!!
    Last edited by Lykurg; 17th December 2011 at 21:28. Reason: missing [code] tags

  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: QtSQL and databse

    Hi,

    see the second parameter of QSqlDatabase::addDatabase() and use it in conjunction with QSqlDatabase::database() to access the database from everywhere in your application.

    Only open the database at start and it will stay open (normally). Or make a global function which always checks if it is open if a local test is to much coding for you.

  3. #3
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QtSQL and databse

    thats perfect thanks

Similar Threads

  1. QtSql or QtSql/ ?
    By szisziszilvi in forum Newbie
    Replies: 3
    Last Post: 8th March 2011, 15:44
  2. adding image into a databse using sqlite
    By pankaj.1426 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 20th October 2010, 10:08
  3. link the content og a QComboBox to a databse table
    By graciano in forum Qt Programming
    Replies: 2
    Last Post: 16th June 2010, 21:08
  4. Need info about databse in qt4
    By newtowindows in forum Installation and Deployment
    Replies: 1
    Last Post: 28th October 2009, 14:42
  5. Stored Procedure in Firebird databse (IBase)
    By Specialized1 in forum Qt Programming
    Replies: 2
    Last Post: 15th September 2009, 09:47

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.