Results 1 to 5 of 5

Thread: Like a session in PHP

  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 Like a session in PHP

    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 

    Then, 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 

    I think that is like set $_SESSION["hostName"]="abc" in PHP.
    How to create like that with Qt ?

  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: Like a session in PHP

    Please, do not post multiple the same issue, and this one I haven't understand... Just because of your former post...

    Look for a Singleton pattern.

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

    Question Re: Like a session in PHP

    Okh

    I can get my variable value in every where with that ?

    I want have a function like $_SESSION[..] in PHP. So if I need the variable value in other dialog, i not need pass the variable to other dialog any more.

    Sorry, with my english..

  4. #4
    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: Like a session in PHP

    Quote Originally Posted by wirasto View Post
    I can get my variable value in every where with that ?
    Have you take a look at it? Yes you can, that's the reason I post it

    Qt Code:
    1. int abc = Singleton::instance()->getMyFancyVariable();
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Lykurg for this useful post:

    wirasto (17th November 2009)

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Like a session in PHP

    Just to make it clear - $_SESSION is not global anymore in php so you can't access it from anywhere in your script unless you register it as global. And if you do, it's direct equivalent in C++ is a global variable as well.

    Qt Code:
    1. QHash<QString,QVariant> _SESSION; // in cpp somewhere
    2. //...
    3. extern QHash<QString,QVariant> _SESSION; // in .h
    4. // ...
    5.  
    6. _SESSION["x"] = "y";
    To copy to clipboard, switch view to plain text mode 

    Of course it's much better to use a singleton as suggested, both in C++ and PHP.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    wirasto (17th November 2009)

Similar Threads

  1. qApp->sessionId() does not gives session id on Mac OS X
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2009, 09:37
  2. Session question
    By MarkoSan in forum Qt Tools
    Replies: 8
    Last Post: 4th July 2009, 02:55
  3. Replies: 0
    Last Post: 26th October 2008, 13:56
  4. Qt: Session management error
    By sabeesh in forum Qt Programming
    Replies: 2
    Last Post: 4th July 2008, 08:10
  5. Query @ SESSION
    By ashukla in forum General Programming
    Replies: 3
    Last Post: 15th May 2008, 11:19

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.