Results 1 to 6 of 6

Thread: Explaination of code required

  1. #1
    Join Date
    Mar 2011
    Location
    INDIA
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Explaination of code required

    Hey ,I am a student learning QT using C/C++.I started doing network examples few days back and wasn't able to understand the following snippet from an example.
    Pls help me understand it.



    Qt Code:
    1. QNetworkConfigurationManager manager;
    2. if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
    3. // Get saved network configuration
    4. QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
    5. settings.beginGroup(QLatin1String("QtNetwork"));
    6. const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
    7. settings.endGroup();
    8.  
    9. // If the saved network configuration is not currently discovered use the system default
    10. QNetworkConfiguration config = manager.configurationFromIdentifier(id);
    11. if ((config.state() & QNetworkConfiguration::Discovered) !=
    12. QNetworkConfiguration::Discovered) {
    13. config = manager.defaultConfiguration();
    14. }
    To copy to clipboard, switch view to plain text mode 

    thanks
    Arpit

  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: Explaination of code required

    What exactly do you don't understand?

  3. #3
    Join Date
    Mar 2011
    Location
    INDIA
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Explaination of code required

    Qt Code:
    1. Settings settings(QSettings::UserScope, QLatin1String("Trolltech"));
    2. settings.beginGroup(QLatin1String("QtNetwork"));
    3. const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
    To copy to clipboard, switch view to plain text mode 

    I wasn't able to understand how is this part working that is how it is getting the configrations, and especially Qlatin1string(" ") . Well this snippet is from Qt example Fortune server/client. Can i run this prg on diffrent machines i.e one with server another with client.

  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: Explaination of code required

    Ok, see Client::sessionOpened(). There the connection is stored, when it was successful. So in your code QSettings is only used to verify if there was a already working session and if so, this should be used. Therefore the normal QSettings syntax is used. There is a good example in the detailed description of QSettings on how to store and get settings back. Also on where to store these settings (the parameters of the c-tor).
    As for the QLatin1String. It is just a small wrapper to avoid using the heavy QString. The purpose is to keep the compiler silent if you use QT_NO_CAST_FROM_ASCII. It may be important if you use translations within your application.

  5. #5
    Join Date
    Mar 2011
    Location
    INDIA
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Explaination of code required

    Thanks , pls correct me if I am wrong

    So, QLatin1String(" Trolltech ") means it is using Trolltech object to access trolltech server setting & store it.

    If yes then how do i access a computer on network of which only IP address is known to me.

  6. #6
    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: Explaination of code required

    No, QSettings only uses a local file to store a once made connection (The one after you have pressed the get fortune button). And that has nothing to do with Trolltech. It is just a name to identify the settings object (file). See QCoreApplication::setOrganizationName().

    how do i access a computer on network of which only IP address is known to me.
    Fill in the informations at server name and server port.

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

    Arpitgarg (9th March 2011)

Similar Threads

  1. QT minimal Glut code - no library linking required
    By rucs_hack in forum Qt Programming
    Replies: 5
    Last Post: 3rd October 2013, 08:30
  2. Qt 4.5.0 Required
    By jsmith in forum Installation and Deployment
    Replies: 4
    Last Post: 7th September 2009, 06:37

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.