Qt 4.8
Public Types | Static Public Functions | Private Functions | List of all members
QLibraryInfo Class Reference

The QLibraryInfo class provides information about the Qt library. More...

#include <qlibraryinfo.h>

Public Types

enum  LibraryLocation {
  PrefixPath, DocumentationPath, HeadersPath, LibrariesPath,
  BinariesPath, PluginsPath, DataPath, TranslationsPath,
  SettingsPath, DemosPath, ExamplesPath, ImportsPath
}
 This enum type is used to specify a specific location specifier: More...
 

Static Public Functions

static QDate buildDate ()
 Returns the installation date for this build of Qt. More...
 
static QString buildKey ()
 Returns a unique key identifying this build of Qt and its configurations. More...
 
static QString licensedProducts ()
 Returns the products that the license for this build of Qt has access to. More...
 
static QString licensee ()
 Returns the person to whom this build of Qt is licensed. More...
 
static QString location (LibraryLocation)
 Returns the location specified by loc. More...
 

Private Functions

 QLibraryInfo ()
 You cannot create a QLibraryInfo, instead only the static functions are available to query information. More...
 

Detailed Description

The QLibraryInfo class provides information about the Qt library.

Many pieces of information are established when Qt is configured. Installation paths, license information, and even a unique build key. This class provides an abstraction for accessing this information.

Function Return value
buildKey() A string that identifies the Qt version and the configuration. This key is used to ensure that plugins link against the same version of Qt as the application.
location() The path to a certain Qt component (e.g., documentation, header files).
licensee(), licensedProducts() Licensing information.

You can also use a qt.conf file to override the hard-coded paths that are compiled into the Qt library. For more information, see the {Using qt.conf} documentation.

See also
QSysInfo, {Using qt.conf}

Definition at line 56 of file qlibraryinfo.h.

Enumerations

◆ LibraryLocation

This enum type is used to specify a specific location specifier:

  • PrefixPath The default prefix for all paths.

library location

  • DocumentationPath The location for documentation upon install.
  • HeadersPath The location for all headers.
  • LibrariesPath The location of installed libraries.
  • BinariesPath The location of installed Qt binaries (tools and applications).
  • PluginsPath The location of installed Qt plugins.
  • ImportsPath The location of installed QML extensions to import.
  • DataPath The location of general Qt data.
  • TranslationsPath The location of translation information for Qt strings.
  • SettingsPath The location for Qt settings.
  • ExamplesPath The location for examples upon install.
  • DemosPath The location for demos upon install.
See also
location()
Enumerator
PrefixPath 
DocumentationPath 
HeadersPath 
LibrariesPath 
BinariesPath 
PluginsPath 
DataPath 
TranslationsPath 
SettingsPath 
DemosPath 
ExamplesPath 
ImportsPath 

Definition at line 67 of file qlibraryinfo.h.

Constructors and Destructors

◆ QLibraryInfo()

QLibraryInfo::QLibraryInfo ( )
private

You cannot create a QLibraryInfo, instead only the static functions are available to query information.

Warning
This function is not part of the public interface.

Definition at line 182 of file qlibraryinfo.cpp.

183 { }

Functions

◆ buildDate()

QDate QLibraryInfo::buildDate ( )
static

Returns the installation date for this build of Qt.

Since
4.6 The install date will usually be the last time that Qt sources were configured.

Definition at line 236 of file qlibraryinfo.cpp.

Referenced by qt_eval_days_left().

237 {
238  return QDate::fromString(QString::fromLatin1(qt_configure_installation + 12), Qt::ISODate);
239 }
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static QDate fromString(const QString &s, Qt::DateFormat f=Qt::TextDate)
Returns the QDate represented by the string, using the format given, or an invalid date if the string...
Definition: qdatetime.cpp:1203

◆ buildKey()

QString QLibraryInfo::buildKey ( )
static

Returns a unique key identifying this build of Qt and its configurations.

This key is not globally unique, rather only useful for establishing of two configurations are compatible. This can be used to compare with the QT_BUILD_KEY preprocessor symbol.

See also
location()

Definition at line 221 of file qlibraryinfo.cpp.

222 {
224 }
#define QT_BUILD_KEY
Definition: qglobal.h:1254
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ licensedProducts()

QString QLibraryInfo::licensedProducts ( )
static

Returns the products that the license for this build of Qt has access to.

See also
licensee()

Definition at line 205 of file qlibraryinfo.cpp.

206 {
207  const char *str = QT_CONFIGURE_LICENSED_PRODUCTS;
208  return QString::fromLatin1(str);
209 }
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ licensee()

QString QLibraryInfo::licensee ( )
static

Returns the person to whom this build of Qt is licensed.

See also
licensedProducts()

Definition at line 192 of file qlibraryinfo.cpp.

Referenced by qt_eval_string().

193 {
194  const char *str = QT_CONFIGURE_LICENSEE;
195  return QString::fromLocal8Bit(str);
196 }
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245

◆ location()

QString QLibraryInfo::location ( LibraryLocation  loc)
static

Returns the location specified by loc.

Definition at line 248 of file qlibraryinfo.cpp.

Referenced by QCoreApplicationPrivate::appendApplicationPathToLibraryPaths(), QPlatformFontDatabase::fontDir(), initDefaultPaths(), QCoreApplication::libraryPaths(), QDeclarativeImportDatabase::QDeclarativeImportDatabase(), QFontEngineQPF::QFontEngineQPF(), qwsFontPath(), QFactoryLoader::refreshAll(), and QCoreApplication::removeLibraryPath().

249 {
250  QString ret;
252  const char *path = 0;
253  switch (loc) {
254 #ifdef QT_CONFIGURE_PREFIX_PATH
255  case PrefixPath:
256  path = QT_CONFIGURE_PREFIX_PATH;
257  break;
258 #endif
259 #ifdef QT_CONFIGURE_DOCUMENTATION_PATH
260  case DocumentationPath:
261  path = QT_CONFIGURE_DOCUMENTATION_PATH;
262  break;
263 #endif
264 #ifdef QT_CONFIGURE_HEADERS_PATH
265  case HeadersPath:
266  path = QT_CONFIGURE_HEADERS_PATH;
267  break;
268 #endif
269 #ifdef QT_CONFIGURE_LIBRARIES_PATH
270  case LibrariesPath:
271  path = QT_CONFIGURE_LIBRARIES_PATH;
272  break;
273 #endif
274 #ifdef QT_CONFIGURE_BINARIES_PATH
275  case BinariesPath:
276  path = QT_CONFIGURE_BINARIES_PATH;
277  break;
278 #endif
279 #ifdef QT_CONFIGURE_PLUGINS_PATH
280  case PluginsPath:
281  path = QT_CONFIGURE_PLUGINS_PATH;
282  break;
283 #endif
284 #ifdef QT_CONFIGURE_IMPORTS_PATH
285  case ImportsPath:
286  path = QT_CONFIGURE_IMPORTS_PATH;
287  break;
288 #endif
289 #ifdef QT_CONFIGURE_DATA_PATH
290  case DataPath:
291  path = QT_CONFIGURE_DATA_PATH;
292  break;
293 #endif
294 #ifdef QT_CONFIGURE_TRANSLATIONS_PATH
295  case TranslationsPath:
296  path = QT_CONFIGURE_TRANSLATIONS_PATH;
297  break;
298 #endif
299 #ifdef QT_CONFIGURE_SETTINGS_PATH
300  case SettingsPath:
301  path = QT_CONFIGURE_SETTINGS_PATH;
302  break;
303 #endif
304 #ifdef QT_CONFIGURE_EXAMPLES_PATH
305  case ExamplesPath:
306  path = QT_CONFIGURE_EXAMPLES_PATH;
307  break;
308 #endif
309 #ifdef QT_CONFIGURE_DEMOS_PATH
310  case DemosPath:
311  path = QT_CONFIGURE_DEMOS_PATH;
312  break;
313 #endif
314  default:
315  break;
316  }
317 
318  if (path)
319  ret = QString::fromLocal8Bit(path);
320  } else {
321  QString key;
322  QString defaultValue;
323  switch(loc) {
324  case PrefixPath:
325  key = QLatin1String("Prefix");
326  break;
327  case DocumentationPath:
328  key = QLatin1String("Documentation");
329  defaultValue = QLatin1String("doc");
330  break;
331  case HeadersPath:
332  key = QLatin1String("Headers");
333  defaultValue = QLatin1String("include");
334  break;
335  case LibrariesPath:
336  key = QLatin1String("Libraries");
337  defaultValue = QLatin1String("lib");
338  break;
339  case BinariesPath:
340  key = QLatin1String("Binaries");
341  defaultValue = QLatin1String("bin");
342  break;
343  case PluginsPath:
344  key = QLatin1String("Plugins");
345  defaultValue = QLatin1String("plugins");
346  break;
347  case ImportsPath:
348  key = QLatin1String("Imports");
349  defaultValue = QLatin1String("imports");
350  break;
351  case DataPath:
352  key = QLatin1String("Data");
353  break;
354  case TranslationsPath:
355  key = QLatin1String("Translations");
356  defaultValue = QLatin1String("translations");
357  break;
358  case SettingsPath:
359  key = QLatin1String("Settings");
360  break;
361  case ExamplesPath:
362  key = QLatin1String("Examples");
363  break;
364  case DemosPath:
365  key = QLatin1String("Demos");
366  break;
367  default:
368  break;
369  }
370 
371  if(!key.isNull()) {
373  config->beginGroup(QLatin1String("Paths"));
374 
375  QString subKey;
376  {
377  /*
378  find the child group whose version number is closest
379  to the library version. for example and we have the
380  following groups:
381 
382  Paths
383  Paths/4.0
384  Paths/4.1.2
385  Paths/4.2.5
386  Paths/5
387 
388  if QT_VERSION is 4.0.1, then we use 'Paths/4.0'
389  if QT_VERSION is 4.1.5, then we use 'Paths/4.1.2'
390  if QT_VERSION is 4.6.3, then we use 'Paths/4.2.5'
391  if QT_VERSION is 6.0.2, then we use 'Paths/5'
392 
393  note: any of the trailing version numbers may be
394  omitted (in which case, they default to zero),
395  i.e. 4 == 4.0.0, 4.1 == 4.1.0, and so on
396  */
397  enum {
398  QT_MAJOR = ((QT_VERSION >> 16) & 0xFF),
399  QT_MINOR = ((QT_VERSION >> 8) & 0xFF),
400  QT_PATCH = (QT_VERSION & 0xFF)
401  };
402  int maj = 0, min = 0, pat = 0;
403  QStringList children = config->childGroups();
404  for(int child = 0; child < children.size(); ++child) {
405  QString cver = children.at(child);
406  QStringList cver_list = cver.split(QLatin1Char('.'));
407  if(cver_list.size() > 0 && cver_list.size() < 4) {
408  bool ok;
409  int cmaj = -1, cmin = -1, cpat = -1;
410  cmaj = cver_list[0].toInt(&ok);
411  if(!ok || cmaj < 0)
412  continue;
413  if(cver_list.size() >= 2) {
414  cmin = cver_list[1].toInt(&ok);
415  if(!ok)
416  continue;
417  if(cmin < 0)
418  cmin = -1;
419  }
420  if(cver_list.size() >= 3) {
421  cpat = cver_list[2].toInt(&ok);
422  if(!ok)
423  continue;
424  if(cpat < 0)
425  cpat = -1;
426  }
427  if((cmaj >= maj && cmaj <= QT_MAJOR) &&
428  (cmin == -1 || (cmin >= min && cmin <= QT_MINOR)) &&
429  (cpat == -1 || (cpat >= pat && cpat <= QT_PATCH)) &&
430  config->contains(cver + QLatin1Char('/') + key)) {
431  subKey = cver + QLatin1Char('/');
432  maj = cmaj;
433  min = cmin;
434  pat = cpat;
435  }
436  }
437  }
438  }
439  ret = config->value(subKey + key, defaultValue).toString();
440  // expand environment variables in the form $(ENVVAR)
441  int rep;
442  QRegExp reg_var(QLatin1String("\\$\\(.*\\)"));
443  reg_var.setMinimal(true);
444  while((rep = reg_var.indexIn(ret)) != -1) {
445  ret.replace(rep, reg_var.matchedLength(),
446  QString::fromLocal8Bit(qgetenv(ret.mid(rep + 2,
447  reg_var.matchedLength() - 3).toLatin1().constData()).constData()));
448  }
449 
450 #ifdef QLIBRARYINFO_EPOCROOT
451  // $${EPOCROOT} is a special case, resolve it similarly to qmake.
452  QRegExp epocrootMatcher(QLatin1String("\\$\\$\\{EPOCROOT\\}"));
453  if ((rep = epocrootMatcher.indexIn(ret)) != -1)
454  ret.replace(rep, epocrootMatcher.matchedLength(), qt_epocRoot());
455 #endif
456 
457  config->endGroup();
458  }
459  }
460 
461  if (QDir::isRelativePath(ret)) {
462  QString baseDir;
463  if (loc == PrefixPath) {
464  // we make the prefix path absolute to the executable's directory
465 #ifdef BOOTSTRAPPING
466  baseDir = QFileInfo(qmake_libraryInfoFile()).absolutePath();
467 #else
469 #ifdef Q_OS_MAC
470  CFBundleRef bundleRef = CFBundleGetMainBundle();
471  if (bundleRef) {
472  QCFType<CFURLRef> urlRef = CFBundleCopyBundleURL(bundleRef);
473  if (urlRef) {
474  QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
475  return QDir::cleanPath(QString(path) + QLatin1String("/Contents/") + ret);
476  }
477  }
478 #endif
480  } else {
481  baseDir = QDir::currentPath();
482  }
483 #endif
484  } else {
485  // we make any other path absolute to the prefix directory
486  baseDir = location(PrefixPath);
487  }
488  ret = QDir::cleanPath(baseDir + QLatin1Char('/') + ret);
489  }
490  return ret;
491 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Definition: qsettings.cpp:3460
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
Definition: qsettings.cpp:3089
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
static QSettings * configuration()
void beginGroup(const QString &prefix)
Appends prefix to the current group.
Definition: qsettings.cpp:3073
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
Definition: qdir.cpp:2210
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
Definition: qsettings.cpp:3288
static QString applicationDirPath()
Returns the directory that contains the application executable.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
static QString location(LibraryLocation)
Returns the location specified by loc.
int key
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool contains(const QString &key) const
Returns true if there exists a setting called key; returns false otherwise.
Definition: qsettings.cpp:3394
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QString absolutePath() const
Returns a file&#39;s path absolute path.
Definition: qfileinfo.cpp:577
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
#define QT_VERSION
This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that spe...
Definition: qglobal.h:51

The documentation for this class was generated from the following files: