本文整理汇总了C++中QLocale::country方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocale::country方法的具体用法?C++ QLocale::country怎么用?C++ QLocale::country使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocale
的用法示例。
在下文中一共展示了QLocale::country方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName("DoubanFM");
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
//QResource::registerResource("icons.qrc");
QTranslator translator;
QLocale locale;
translator.load(QString(":/lang/")
+ QLocale::countryToString(locale.country())
+ QString("_")
+ QLocale::languageToString(locale.language()));
qDebug() << QString("Load Language: ")
+ QLocale::countryToString(locale.country())
+ QString("_")
+ QLocale::languageToString(locale.language());
a.installTranslator(&translator);
MainWidget mw;
mw.show();
return a.exec();
}
示例2: QWidget
GreetingPage::GreetingPage( QWidget* parent )
: QWidget( parent )
, ui( new Ui::GreetingPage )
{
ui->setupUi( this );
QString defaultLocale = QLocale::system().name();
{
foreach ( const QString& locale, QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') )
{
QLocale thisLocale = QLocale( locale );
QString lang = QLocale::languageToString( thisLocale.language() );
if ( QLocale::countriesForLanguage( thisLocale.language() ).count() > 2 )
lang.append( QString( " (%1)" )
.arg( QLocale::countryToString( thisLocale.country() ) ) );
ui->languageWidget->addItem( lang );
ui->languageWidget->item( ui->languageWidget->count() - 1 )
->setData( Qt::UserRole, thisLocale );
if ( thisLocale.language() == QLocale( defaultLocale ).language() &&
thisLocale.country() == QLocale( defaultLocale ).country() )
ui->languageWidget->setCurrentRow( ui->languageWidget->count() - 1 );
}
ui->languageWidget->sortItems();
connect( ui->languageWidget, &QListWidget::currentItemChanged,
this, [ & ]( QListWidgetItem *current, QListWidgetItem *previous )
{
QLocale selectedLocale = current->data( Qt::UserRole ).toLocale();
cDebug() << "Selected locale" << selectedLocale.name();
QLocale::setDefault( selectedLocale );
CalamaresUtils::installTranslator( selectedLocale.name(), qApp );
} );
connect( ui->languageWidget, &QListWidget::itemDoubleClicked,
this, []
{
Calamares::ViewManager::instance()->next();
} );
}
ui->mainText->setAlignment( Qt::AlignCenter );
ui->mainText->setWordWrap( true );
ui->mainText->setOpenExternalLinks( true );
CALAMARES_RETRANSLATE(
ui->mainText->setText( tr( "<h1>Welcome to the %1 installer.</h1><br/>"
"This program will ask you some questions and "
"set up %2 on your computer." )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::VersionedName ) )
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::ProductName ) ) );
)
示例3: fillComboBoxLanguages
/**
* Read the available language files and fill the combo box.
*/
void SettingsWidget::fillComboBoxLanguages()
{
QVariant dataEn;
dataEn.setValue(Common::Language { "", QLocale("en") });
this->ui->cmbLanguages->addItem("English", dataEn);
QLocale current = QLocale::system();
if (SETTINGS.isSet("language"))
current = SETTINGS.get<QLocale>("language");
this->coreConnection->setCoreLanguage(current);
bool exactMatchFound = false;
Common::Languages langs(QCoreApplication::applicationDirPath() + "/" + Common::Constants::LANGUAGE_DIRECTORY);
for (QListIterator<Common::Language> i(langs.getAvailableLanguages(Common::Languages::ExeType::GUI)); i.hasNext();)
{
Common::Language lang = i.next();
QVariant data;
data.setValue(lang);
this->ui->cmbLanguages->addItem(lang.locale.nativeLanguageName(), data);
if (!exactMatchFound && lang.locale.language() == current.language())
{
exactMatchFound = lang.locale.country() == current.country();
this->ui->cmbLanguages->setCurrentIndex(this->ui->cmbLanguages->count() - 1);
}
}
}
示例4: QStandardItem
void AcceptLangWidget::AddLocale (const QLocale& locale)
{
QList<QStandardItem*> items;
items << new QStandardItem (QLocale::languageToString (locale.language ()));
items << new QStandardItem (QLocale::countryToString (locale.country ()));
items << new QStandardItem (Util::GetInternetLocaleName (locale));
Model_->appendRow (items);
items.first ()->setData (locale, Roles::LocaleObj);
}
示例5: nameForLanguage
QString Speller::nameForLanguage(const QString &code) const
{
QLocale loc = QLocale(code);
QString name = QLocale::languageToString(loc.language());
if (loc.country() != QLocale::AnyCountry) {
name.append(" / " + loc.nativeLanguageName());
}
return name;
}
示例6: setLocale
void InfoWidget::localeChanged(QLocale locale)
{
setLocale(locale);
name->setText(locale.name());
bcp47Name->setText(locale.bcp47Name());
languageName->setText(QLocale::languageToString(locale.language()));
nativeLanguageName->setText(locale.nativeLanguageName());
scriptName->setText(QLocale::scriptToString(locale.script()));
countryName->setText(QLocale::countryToString(locale.country()));
nativeCountryName->setText(locale.nativeCountryName());
}
示例7: load
bool PhraseBook::load(const QString &fileName, bool *langGuessed)
{
QFile f(fileName);
if (!f.open(QIODevice::ReadOnly))
return false;
m_fileName = fileName;
QXmlInputSource in(&f);
QXmlSimpleReader reader;
// don't click on these!
reader.setFeature(QLatin1String("http://xml.org/sax/features/namespaces"), false);
reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true);
reader.setFeature(QLatin1String("http://trolltech.com/xml/features/report-whitespace"
"-only-CharData"), false);
QphHandler *hand = new QphHandler(this);
reader.setContentHandler(hand);
reader.setErrorHandler(hand);
bool ok = reader.parse(in);
reader.setContentHandler(0);
reader.setErrorHandler(0);
Translator::languageAndCountry(hand->language(), &m_language, &m_country);
*langGuessed = false;
if (m_language == QLocale::C) {
QLocale sys;
m_language = sys.language();
m_country = sys.country();
*langGuessed = true;
}
QString lang = hand->sourceLanguage();
if (lang.isEmpty()) {
m_sourceLanguage = QLocale::C;
m_sourceCountry = QLocale::AnyCountry;
} else {
Translator::languageAndCountry(lang, &m_sourceLanguage, &m_sourceCountry);
}
delete hand;
f.close();
if (!ok) {
qDeleteAll(m_phrases);
m_phrases.clear();
} else {
emit listChanged();
}
return ok;
}
示例8: foreach
void SetupPluginsDialog::onCurrentLanguageChanged(int AIndex)
{
ui.cmbCountry->clear();
QLocale::Language lang = (QLocale::Language)ui.cmbLanguage->itemData(AIndex).toInt();
foreach (QLocale::Country country, QLocale::countriesForLanguage(lang))
ui.cmbCountry->addItem(QLocale::countryToString(country),(int)country);
ui.cmbCountry->model()->sort(0, Qt::AscendingOrder);
if (lang != QLocale::C)
ui.cmbCountry->insertItem(0,tr("<Any Country>"), QLocale::AnyCountry);
QLocale locale;
if (locale.language() == lang)
ui.cmbCountry->setCurrentIndex(ui.cmbCountry->findData((int)locale.country()));
else
ui.cmbCountry->setCurrentIndex(0);
}
示例9: QComboBox
LocaleSelector::LocaleSelector(QWidget *parent)
: QComboBox(parent)
{
int curIndex = -1;
QLocale curLocale;
for (int i = 0; i < SUPPORTED_LOCALES_COUNT; ++i) {
const SupportedLocale &l = SUPPORTED_LOCALES[i];
if (l.lang == curLocale.language() && l.country == curLocale.country())
curIndex = i;
QString text = QLocale::languageToString(QLocale::Language(l.lang))
+ QLatin1Char('/')
+ QLocale::countryToString(QLocale::Country(l.country));
addItem(text, qVariantFromValue(l));
}
setCurrentIndex(curIndex);
connect(this, SIGNAL(activated(int)), this, SLOT(emitLocaleSelected(int)));
}
示例10: QMainWindow
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{
tc = NULL;
mp3File = NULL;
// icon
setWindowIcon(WIN_ICON);
// Qt Translator
trans = new QTranslator();
QApplication::instance()->installTranslator(trans);
// load default language
QLocale *loc = new QLocale();
language = loc->language() == QLocale::Chinese? loc->country() == QLocale::China? ZHS: ZHT: ENG;
delete loc;
std::cout << "language: " << language << std::endl;
// initial interface
initWidget();
updateInterface();
}
示例11: main
int main(int argc, char *argv[])
{
int Lang = 1; // language
QString home = QDir::homePath();
QTranslator translator;
QLocale locale;
Lang = locale.country(); // 82 for Germany
Lang = 100; // only for TEST dl1hbd - country outside Germany
QApplication a(argc, argv);
if(Lang != 82) { // every country except Germany
home+="/log/qtlogDiag/qtlogaddQso_en";
translator.load(home);
a.installTranslator(&translator);
}
addQso addDiag;
addDiag.show();
return a.exec();
}
示例12: QDialog
AcceptLanguage::AcceptLanguage(QWidget* parent)
: QDialog(parent)
, ui(new Ui::AcceptLanguage)
{
ui->setupUi(this);
Settings settings;
settings.beginGroup("Language");
QStringList langs = settings.value("acceptLanguage", defaultLanguage()).toStringList();
foreach(const QString & code, langs) {
QString code_ = code;
QLocale loc = QLocale(code_.replace('-', '_'));
QString label;
if (loc.language() == QLocale::C) {
label = tr("Personal [%1]").arg(code);
}
else {
label = QString("%1/%2 [%3]").arg(loc.languageToString(loc.language()), loc.countryToString(loc.country()), code);
}
ui->listWidget->addItem(label);
}
示例13: load
bool MessageModel::load(const QString &fileName)
{
MetaTranslator tor;
bool ok = tor.load(fileName);
if (ok) {
if(tor.codecForTr())
m_codecForTr = tor.codecForTr()->name();
int messageCount = 0;
clearContextList();
m_numFinished = 0;
m_numNonobsolete = 0;
TML all = tor.messages();
QHash<QString, ContextItem*> contexts;
m_srcWords = 0;
m_srcChars = 0;
m_srcCharsSpc = 0;
foreach(MetaTranslatorMessage mtm, all) {
QCoreApplication::processEvents();
ContextItem *c;
if (contexts.contains(QLatin1String(mtm.context()))) {
c = contexts.value( QLatin1String(mtm.context()));
}
else {
c = createContextItem(tor.toUnicode(mtm.context(), mtm.utf8()));;
appendContextItem(c);
contexts.insert(QLatin1String(mtm.context()), c);
}
if (QByteArray(mtm.sourceText()) == ContextComment) {
c->appendToComment(tor.toUnicode(mtm.comment(), mtm.utf8()));
}
else {
MessageItem *tmp = new MessageItem(mtm, tor.toUnicode(mtm.sourceText(),
mtm.utf8()), tor.toUnicode(mtm.comment(), mtm.utf8()), c);
if (mtm.type() != MetaTranslatorMessage::Obsolete) {
m_numNonobsolete++;
//if (mtm.type() == MetaTranslatorMessage::Finished)
//tmp->setFinished(true);
//++m_numFinished;
doCharCounting(tmp->sourceText(), m_srcWords, m_srcChars, m_srcCharsSpc);
}
else {
c->incrementObsoleteCount();
}
c->appendMessageItem(tmp);
++messageCount;
}
}
// Try to detect the correct language in the following order
// 1. Look for the language attribute in the ts
// if that fails
// 2. Guestimate the language from the filename (expecting the qt_{en,de}.ts convention)
// if that fails
// 3. Retrieve the locale from the system.
QString lang = tor.languageCode();
if (lang.isEmpty()) {
int pos_sep = fileName.indexOf(QLatin1Char('_'));
if (pos_sep != -1 && pos_sep + 3 <= fileName.length()) {
lang = fileName.mid(pos_sep + 1, 2);
}
}
QLocale::Language l;
QLocale::Country c;
MetaTranslator::languageAndCountry(lang, &l, &c);
if (l == QLocale::C) {
QLocale sys;
l = sys.language();
c = sys.country();
}
setLanguage(l);
setCountry(c);
m_numMessages = messageCount;
updateAll();
setModified(false);
}
示例14: interpretResourceFile
bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice,
const QString &fname, QString currentPath, bool ignoreErrors)
{
Q_ASSERT(m_errorDevice);
const QChar slash = QLatin1Char('/');
if (!currentPath.isEmpty() && !currentPath.endsWith(slash))
currentPath += slash;
QXmlStreamReader reader(inputDevice);
QStack<RCCXmlTag> tokens;
QString prefix;
QLocale::Language language = QLocale::c().language();
QLocale::Country country = QLocale::c().country();
QString alias;
int compressLevel = m_compressLevel;
int compressThreshold = m_compressThreshold;
while (!reader.atEnd()) {
QXmlStreamReader::TokenType t = reader.readNext();
switch (t) {
case QXmlStreamReader::StartElement:
if (reader.name() == m_strings.TAG_RCC) {
if (!tokens.isEmpty())
reader.raiseError(QLatin1String("expected <RCC> tag"));
else
tokens.push(RccTag);
} else if (reader.name() == m_strings.TAG_RESOURCE) {
if (tokens.isEmpty() || tokens.top() != RccTag) {
reader.raiseError(QLatin1String("unexpected <RESOURCE> tag"));
} else {
tokens.push(ResourceTag);
QXmlStreamAttributes attributes = reader.attributes();
language = QLocale::c().language();
country = QLocale::c().country();
if (attributes.hasAttribute(m_strings.ATTRIBUTE_LANG)) {
QString attribute = attributes.value(m_strings.ATTRIBUTE_LANG).toString();
QLocale lang = QLocale(attribute);
language = lang.language();
if (2 == attribute.length()) {
// Language only
country = QLocale::AnyCountry;
} else {
country = lang.country();
}
}
prefix.clear();
if (attributes.hasAttribute(m_strings.ATTRIBUTE_PREFIX))
prefix = attributes.value(m_strings.ATTRIBUTE_PREFIX).toString();
if (!prefix.startsWith(slash))
prefix.prepend(slash);
if (!prefix.endsWith(slash))
prefix += slash;
}
} else if (reader.name() == m_strings.TAG_FILE) {
if (tokens.isEmpty() || tokens.top() != ResourceTag) {
reader.raiseError(QLatin1String("unexpected <FILE> tag"));
} else {
tokens.push(FileTag);
QXmlStreamAttributes attributes = reader.attributes();
alias.clear();
if (attributes.hasAttribute(m_strings.ATTRIBUTE_ALIAS))
alias = attributes.value(m_strings.ATTRIBUTE_ALIAS).toString();
compressLevel = m_compressLevel;
if (attributes.hasAttribute(m_strings.ATTRIBUTE_COMPRESS))
compressLevel = attributes.value(m_strings.ATTRIBUTE_COMPRESS).toString().toInt();
compressThreshold = m_compressThreshold;
if (attributes.hasAttribute(m_strings.ATTRIBUTE_THRESHOLD))
compressThreshold = attributes.value(m_strings.ATTRIBUTE_THRESHOLD).toString().toInt();
// Special case for -no-compress. Overrides all other settings.
if (m_compressLevel == -2)
compressLevel = 0;
}
} else {
reader.raiseError(QString(QLatin1String("unexpected tag: %1")).arg(reader.name().toString()));
}
break;
case QXmlStreamReader::EndElement:
if (reader.name() == m_strings.TAG_RCC) {
if (!tokens.isEmpty() && tokens.top() == RccTag)
tokens.pop();
else
reader.raiseError(QLatin1String("unexpected closing tag"));
} else if (reader.name() == m_strings.TAG_RESOURCE) {
if (!tokens.isEmpty() && tokens.top() == ResourceTag)
tokens.pop();
else
reader.raiseError(QLatin1String("unexpected closing tag"));
} else if (reader.name() == m_strings.TAG_FILE) {
if (!tokens.isEmpty() && tokens.top() == FileTag)
tokens.pop();
else
//.........这里部分代码省略.........
示例15: findNode
int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
{
QString path = _path;
{
QString root = mappingRoot();
if(!root.isEmpty()) {
if(root == path) {
path = QLatin1Char('/');
} else {
if(!root.endsWith(QLatin1Char('/')))
root += QLatin1Char('/');
if(path.size() >= root.size() && path.startsWith(root))
path = path.mid(root.length()-1);
if(path.isEmpty())
path = QLatin1Char('/');
}
}
}
#ifdef DEBUG_RESOURCE_MATCH
qDebug() << "!!!!" << "START" << path << locale.country() << locale.language();
#endif
if(path == QLatin1String("/"))
return 0;
//the root node is always first
int child_count = (tree[6] << 24) + (tree[7] << 16) +
(tree[8] << 8) + (tree[9] << 0);
int child = (tree[10] << 24) + (tree[11] << 16) +
(tree[12] << 8) + (tree[13] << 0);
//now iterate up the tree
int node = -1;
QStringSplitter splitter(path);
while (child_count && splitter.hasNext()) {
QStringRef segment = splitter.next();
#ifdef DEBUG_RESOURCE_MATCH
qDebug() << " CHILDREN" << segment;
for(int j = 0; j < child_count; ++j) {
qDebug() << " " << child+j << " :: " << name(child+j);
}
#endif
const int h = qHash(segment);
//do the binary search for the hash
int l = 0, r = child_count-1;
int sub_node = (l+r+1)/2;
while(r != l) {
const int sub_node_hash = hash(child+sub_node);
if(h == sub_node_hash)
break;
else if(h < sub_node_hash)
r = sub_node - 1;
else
l = sub_node;
sub_node = (l + r + 1) / 2;
}
sub_node += child;
//now do the "harder" compares
bool found = false;
if(hash(sub_node) == h) {
while(sub_node > child && hash(sub_node-1) == h) //backup for collisions
--sub_node;
for(; sub_node < child+child_count && hash(sub_node) == h; ++sub_node) { //here we go...
if(name(sub_node) == segment) {
found = true;
int offset = findOffset(sub_node);
#ifdef DEBUG_RESOURCE_MATCH
qDebug() << " TRY" << sub_node << name(sub_node) << offset;
#endif
offset += 4; //jump past name
const short flags = (tree[offset+0] << 8) +
(tree[offset+1] << 0);
offset += 2;
if(!splitter.hasNext()) {
if(!(flags & Directory)) {
const short country = (tree[offset+0] << 8) +
(tree[offset+1] << 0);
offset += 2;
const short language = (tree[offset+0] << 8) +
(tree[offset+1] << 0);
offset += 2;
#ifdef DEBUG_RESOURCE_MATCH
qDebug() << " " << "LOCALE" << country << language;
#endif
if(country == locale.country() && language == locale.language()) {
#ifdef DEBUG_RESOURCE_MATCH
qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node;
#endif
return sub_node;
} else if((country == QLocale::AnyCountry && language == locale.language()) ||
(country == QLocale::AnyCountry && language == QLocale::C && node == -1)) {
node = sub_node;
}
//.........这里部分代码省略.........