Get OS name: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
<code> QString Get::osName()<br /> {<br /> #if defined(Q_OS_ANDROID)<br /> return QLatin1String(&quot;android&amp;quot;);<br /> #elif defined(Q_OS_BLACKBERRY)<br /> return QLatin1String(&quot;blackberry&amp;quot;);<br /> #elif defined(Q_OS_IOS)<br /> return QLatin1String(&quot;ios&amp;quot;);<br /> #elif defined(Q_OS_MAC)<br /> return QLatin1String(&quot;osx&amp;quot;);<br /> #elif defined(Q_OS_WINCE)<br /> return QLatin1String(&quot;wince&amp;quot;);<br /> #elif defined(Q_OS_WIN)<br /> return QLatin1String(&quot;windows&amp;quot;);<br /> #elif defined(Q_OS_LINUX)<br /> return QLatin1String(&quot;linux&amp;quot;);<br /> #elif defined(Q_OS_UNIX)<br /> return QLatin1String(&quot;unix&amp;quot;);<br /> #else<br /> return QLatin1String(&quot;unknown&amp;quot;);<br /> #endif<br /> }<br /></code>
<code> QString Get::osName()
{
#if defined(Q_OS_ANDROID)
return QLatin1String("android");
#elif defined(Q_OS_BLACKBERRY)
return QLatin1String("blackberry");
#elif defined(Q_OS_IOS)
return QLatin1String("ios");
#elif defined(Q_OS_MAC)
return QLatin1String("osx");
#elif defined(Q_OS_WINCE)
return QLatin1String("wince");
#elif defined(Q_OS_WIN)
return QLatin1String("windows");
#elif defined(Q_OS_LINUX)
return QLatin1String("linux");
#elif defined(Q_OS_UNIX)
return QLatin1String("unix");
#else
return QLatin1String("unknown");
#endif
}
</code>


If single required
If single required


<code><br />#ifdef Q_OS_LINUX<br />return QString::fromLatin1(DATADIR&amp;quot;/&amp;quot;APPLICATION_EXECUTABLE&amp;quot;/i18n/&amp;quot;);<br />#endif<br />#ifdef Q_OS_MAC<br />return QApplication::applicationDirPath()+QLatin1String(&quot;/../Resources/Translations&amp;quot;); // path defaults to app dir.<br />#endif<br />#ifdef Q_OS_WIN<br />return QApplication::applicationDirPath();
<code>
#ifdef Q_OS_LINUX
return QString::fromLatin1(DATADIR"/"APPLICATION_EXECUTABLE"/i18n/");
#endif
#ifdef Q_OS_MAC
return QApplication::applicationDirPath()+QLatin1String("/../Resources/Translations"); // path defaults to app dir.
#endif
#ifdef Q_OS_WIN
return QApplication::applicationDirPath();

Revision as of 10:54, 25 February 2015

 QString Get::osName()
 {
 #if defined(Q_OS_ANDROID)
 return QLatin1String("android");
 #elif defined(Q_OS_BLACKBERRY)
 return QLatin1String("blackberry");
 #elif defined(Q_OS_IOS)
 return QLatin1String("ios");
 #elif defined(Q_OS_MAC)
 return QLatin1String("osx");
 #elif defined(Q_OS_WINCE)
 return QLatin1String("wince");
 #elif defined(Q_OS_WIN)
 return QLatin1String("windows");
 #elif defined(Q_OS_LINUX)
 return QLatin1String("linux");
 #elif defined(Q_OS_UNIX)
 return QLatin1String("unix");
 #else
 return QLatin1String("unknown");
 #endif
 }

If single required

  1. ifdef Q_OS_LINUX

return QString::fromLatin1(DATADIR"/"APPLICATION_EXECUTABLE"/i18n/");

  1. endif
  2. ifdef Q_OS_MAC

return QApplication::applicationDirPath()+QLatin1String("/../Resources/Translations"); // path defaults to app dir.

  1. endif
  2. ifdef Q_OS_WIN

return QApplication::applicationDirPath();