Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How to get QLocale by QLocale::Country
QtWS25 Last Chance

[SOLVED] How to get QLocale by QLocale::Country

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxim.prishchepa
    wrote on last edited by
    #1

    Hi Al!!
    I have a list of countries such a:
    @for (int i = 1; i < QLocale::LastCountry-1; ++i) {
    //here i need to display native country name, how can i do that?
    }@

    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MrMNight
      wrote on last edited by
      #2

      Hi there. Is "that":http://qt-project.org/doc/qt-5/qlocale.html#countryToString what you want?
      @
      for (int i = 1; i < QLocale::LastCountry-1; ++i)
      {
      qDebug()<<QLocale::countryToString((QLocale::Country)i);
      }
      @

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jan-Willem
        wrote on last edited by
        #3

        Hi,

        I'm not at home so I can't try this right now, but I would try something like this:
        @QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);

        for (int i = 1; i < allLocales. count()-1; ++i) {
        QString nativeCountryName = allLocales.at(i).nativeCountryName();
        }@

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MrMNight
          wrote on last edited by
          #4

          [quote author="Jan-Willem" date="1400243997"]
          @
          for (int i = 1; i < allLocales. count()-1; ++i) {
          QString nativeCountryName = allLocales.nativeCountryName();
          }@
          [/quote]
          you forgot iterator:
          @
          QString nativeCountryName = allLocales.at(i).nativeCountryName();
          @

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jan-Willem
            wrote on last edited by
            #5

            Yep your right. I will update the code.
            Thanks

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maxim.prishchepa
              wrote on last edited by
              #6

              [quote author="Jan-Willem" date="1400243997"]Hi,

              I'm not at home so I can't try this right now, but I would try something like this:
              @QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);

              for (int i = 1; i < allLocales. count()-1; ++i) {
              QString nativeCountryName = allLocales.at(i).nativeCountryName();
              }@
              [/quote]

              A lot of tnx! but this code give around 400 records, when countries count around 250, how can i filter them?

              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maxim.prishchepa
                wrote on last edited by
                #7
                • i don't need all of languages at the country, i need only one language per country.

                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  maxim.prishchepa
                  wrote on last edited by
                  #8

                  and one more, is any body know how can i take a phone number code by CountryCode? Maybe some one know free lib for that?

                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jan-Willem
                    wrote on last edited by
                    #9
                    • Perhaps you could experiment with the values of QLocale::AnyLanguage and QLocale::AnyScript to limit you output.

                    • You could check if nativeCountryName already exists, and when true, don't add it to your list.

                    • Alternatively you could use QMetaEnum to retrieve the values of the enum QLocale::Country, where al the country names are stored. The names of the countries are returned by key().

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      maxim.prishchepa
                      wrote on last edited by
                      #10

                      i currently use map for set relation from QLocale::Country to QLocale, this is solve my issue.
                      Once again tnx!
                      about taking phone number code issue is open.

                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved