Results 1 to 3 of 3

Thread: How to get value from everywhere

  1. #1
    Join Date
    May 2009
    Location
    Gorontalo
    Posts
    200
    Thanks
    20
    Thanked 5 Times in 5 Posts
    Qt products
    Platforms
    Unix/X11 Windows

    Question How to get value from everywhere

    I'm so impressed with QSqlDatabase. If I set like this..

    Qt Code:
    1. QSqlDatabase db=QSqlDatabase::addDatabase(...);
    2. db.setHostName("abc");
    To copy to clipboard, switch view to plain text mode 

    I can get value "abc" in everywhere with

    Qt Code:
    1. qDebug() << QSqlDatabase::database().hostName()
    To copy to clipboard, switch view to plain text mode 

    How to create like that...?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get value from everywhere

    if you specified the name for connection in QSqlDatabase::addDatabase then you should use this name when using QSqlDatabase::database.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    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: How to get value from everywhere

    I think you are looking for a Singleton pattern.

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
  •  
Qt is a trademark of The Qt Company.