#include <qlibraryinfo.h>
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.
Definition at line 35 of file qlibraryinfo.h.
Public Types | |
| enum | LibraryLocation |
Static Public Member Functions | |
| static QString | licensee () |
| static QString | licensedProducts () |
| static QString | buildKey () |
| static QString | location (LibraryLocation) |
Private Member Functions | |
| QLibraryInfo () | |
library location
This enum type is used to specify a specific location specifier:
PrefixPath The default prefix for all paths. DocumentationPath The location for documentation upon install. HeadersPath The location for all headers. LibrariesPath The location of installed librarires. BinariesPath The location of installed Qt binaries (tools and applications). PluginsPath The location of installed Qt plugins. 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.
Definition at line 43 of file qlibraryinfo.h.
00044 { 00045 PrefixPath, 00046 DocumentationPath, 00047 HeadersPath, 00048 LibrariesPath, 00049 BinariesPath, 00050 PluginsPath, 00051 DataPath, 00052 TranslationsPath, 00053 SettingsPath, 00054 DemosPath, 00055 ExamplesPath 00056 };
| QLibraryInfo::QLibraryInfo | ( | ) | [private] |
| QString QLibraryInfo::licensee | ( | ) | [static] |
Returns the person to whom this build of Qt is licensed.
Definition at line 172 of file qlibraryinfo.cpp.
References QString::fromLocal8Bit().
00173 { 00174 const char *str = QT_CONFIGURE_LICENSEE; 00175 return QString::fromLocal8Bit(str); 00176 }
Here is the call graph for this function:

| QString QLibraryInfo::licensedProducts | ( | ) | [static] |
Returns the products that the license for this build of Qt has access to.
Definition at line 185 of file qlibraryinfo.cpp.
References QString::fromLatin1().
Referenced by QDesigner::initialize().
00186 { 00187 const char *str = QT_CONFIGURE_LICENSED_PRODUCTS; 00188 return QString::fromLatin1(str); 00189 }
Here is the call graph for this function:

| 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.
Definition at line 201 of file qlibraryinfo.cpp.
References QString::fromLatin1().
00202 { 00203 return QString::fromLatin1(QT_BUILD_KEY); 00204 }
Here is the call graph for this function:

| QString QLibraryInfo::location | ( | LibraryLocation | loc | ) | [static] |
Returns the location specified by loc.
Definition at line 212 of file qlibraryinfo.cpp.
References QDir::absoluteFilePath(), QCoreApplication::applicationDirPath(), QList< T >::at(), QSettings::beginGroup(), BinariesPath, QDir::cleanPath(), QLibraryInfoPrivate::configuration(), constData(), QString::constData(), QDir::current(), DataPath, DemosPath, DocumentationPath, ExamplesPath, QString::fromLocal8Bit(), HeadersPath, QRegExp::indexIn(), QCoreApplication::instance(), QDir::isRelativePath(), key, LibrariesPath, QRegExp::matchedLength(), QString::mid(), path, PluginsPath, PrefixPath, qgetenv(), QT_VERSION, QString::replace(), QRegExp::setMinimal(), SettingsPath, QList< T >::size(), QString::split(), and TranslationsPath.
Referenced by QCoreApplicationPrivate::appendApplicationPathToLibraryPaths(), MainWindow::assistant(), Config::assistantDocPath(), qdesigner_internal::QDesignerResource::create(), Profile::createDefaultProfile(), FeatureTextBrowser::FeatureTextBrowser(), findRulesFile(), getPath(), getPropertyValue(), FindFileDialog::help(), QDesigner::initialize(), MainWindow::initializeAssistant(), Launcher::Launcher(), Launcher::launchExample(), linkify(), Config::load(), Profile::loadableFilePath(), main(), TrWindow::manual(), TrWindow::openPhraseBook(), Q_GLOBAL_STATIC_WITH_ARGS(), qmake_mkspec_paths(), Porting::readXML(), Config::saveProfile(), Launcher::setup(), QDesignerActions::showHelp(), QPixelTool::showHelp(), MainWindow::showQtHelp(), and Profile::storableFilePath().
00213 { 00214 QString ret; 00215 if(!QLibraryInfoPrivate::configuration()) { 00216 const char *path = 0; 00217 switch (loc) { 00218 #ifdef QT_CONFIGURE_PREFIX_PATH 00219 case PrefixPath: 00220 path = QT_CONFIGURE_PREFIX_PATH; 00221 break; 00222 #endif 00223 #ifdef QT_CONFIGURE_DOCUMENTATION_PATH 00224 case DocumentationPath: 00225 path = QT_CONFIGURE_DOCUMENTATION_PATH; 00226 break; 00227 #endif 00228 #ifdef QT_CONFIGURE_HEADERS_PATH 00229 case HeadersPath: 00230 path = QT_CONFIGURE_HEADERS_PATH; 00231 break; 00232 #endif 00233 #ifdef QT_CONFIGURE_LIBRARIES_PATH 00234 case LibrariesPath: 00235 path = QT_CONFIGURE_LIBRARIES_PATH; 00236 break; 00237 #endif 00238 #ifdef QT_CONFIGURE_BINARIES_PATH 00239 case BinariesPath: 00240 path = QT_CONFIGURE_BINARIES_PATH; 00241 break; 00242 #endif 00243 #ifdef QT_CONFIGURE_PLUGINS_PATH 00244 case PluginsPath: 00245 path = QT_CONFIGURE_PLUGINS_PATH; 00246 break; 00247 #endif 00248 #ifdef QT_CONFIGURE_DATA_PATH 00249 case DataPath: 00250 path = QT_CONFIGURE_DATA_PATH; 00251 break; 00252 #endif 00253 #ifdef QT_CONFIGURE_TRANSLATIONS_PATH 00254 case TranslationsPath: 00255 path = QT_CONFIGURE_TRANSLATIONS_PATH; 00256 break; 00257 #endif 00258 #ifdef QT_CONFIGURE_SETTINGS_PATH 00259 case SettingsPath: 00260 path = QT_CONFIGURE_SETTINGS_PATH; 00261 break; 00262 #endif 00263 #ifdef QT_CONFIGURE_EXAMPLES_PATH 00264 case ExamplesPath: 00265 path = QT_CONFIGURE_EXAMPLES_PATH; 00266 break; 00267 #endif 00268 #ifdef QT_CONFIGURE_DEMOS_PATH 00269 case DemosPath: 00270 path = QT_CONFIGURE_DEMOS_PATH; 00271 break; 00272 #endif 00273 default: 00274 break; 00275 } 00276 00277 if (path) 00278 ret = QString::fromLocal8Bit(path); 00279 } else { 00280 QString key; 00281 QString defaultValue; 00282 switch(loc) { 00283 case PrefixPath: 00284 key = QLatin1String("Prefix"); 00285 break; 00286 case DocumentationPath: 00287 key = QLatin1String("Documentation"); 00288 defaultValue = QLatin1String("doc"); 00289 break; 00290 case HeadersPath: 00291 key = QLatin1String("Headers"); 00292 defaultValue = QLatin1String("include"); 00293 break; 00294 case LibrariesPath: 00295 key = QLatin1String("Libraries"); 00296 defaultValue = QLatin1String("lib"); 00297 break; 00298 case BinariesPath: 00299 key = QLatin1String("Binaries"); 00300 defaultValue = QLatin1String("bin"); 00301 break; 00302 case PluginsPath: 00303 key = QLatin1String("Plugins"); 00304 defaultValue = QLatin1String("plugins"); 00305 break; 00306 case DataPath: 00307 key = QLatin1String("Data"); 00308 break; 00309 case TranslationsPath: 00310 key = QLatin1String("Translations"); 00311 defaultValue = QLatin1String("translations"); 00312 break; 00313 case SettingsPath: 00314 key = QLatin1String("Settings"); 00315 break; 00316 case ExamplesPath: 00317 key = QLatin1String("Examples"); 00318 break; 00319 case DemosPath: 00320 key = QLatin1String("Demos"); 00321 break; 00322 default: 00323 break; 00324 } 00325 00326 if(!key.isNull()) { 00327 QSettings *config = QLibraryInfoPrivate::configuration(); 00328 config->beginGroup(QLatin1String("Paths")); 00329 00330 QString subKey; 00331 { 00332 /* 00333 find the child group whose version number is closest 00334 to the library version. for example and we have the 00335 following groups: 00336 00337 Paths 00338 Paths/4.0 00339 Paths/4.1.2 00340 Paths/4.2.5 00341 Paths/5 00342 00343 if QT_VERSION is 4.0.1, then we use 'Paths/4.0' 00344 if QT_VERSION is 4.1.5, then we use 'Paths/4.1.2' 00345 if QT_VERSION is 4.6.3, then we use 'Paths/4.2.5' 00346 if QT_VERSION is 6.0.2, then we use 'Paths/5' 00347 00348 note: any of the trailing version numbers may be 00349 omitted (in which case, they default to zero), 00350 i.e. 4 == 4.0.0, 4.1 == 4.1.0, and so on 00351 */ 00352 enum { 00353 QT_MAJOR = ((QT_VERSION >> 16) & 0xFF), 00354 QT_MINOR = ((QT_VERSION >> 8) & 0xFF), 00355 QT_PATCH = (QT_VERSION & 0xFF) 00356 }; 00357 int maj = 0, min = 0, pat = 0; 00358 QStringList children = config->childGroups(); 00359 for(int child = 0; child < children.size(); ++child) { 00360 QString cver = children.at(child); 00361 QStringList cver_list = cver.split(QLatin1Char('.')); 00362 if(cver_list.size() > 0 && cver_list.size() < 4) { 00363 bool ok; 00364 int cmaj = -1, cmin = -1, cpat = -1; 00365 cmaj = cver_list[0].toInt(&ok); 00366 if(!ok || cmaj < 0) 00367 continue; 00368 if(cver_list.size() >= 2) { 00369 cmin = cver_list[1].toInt(&ok); 00370 if(!ok) 00371 continue; 00372 if(cmin < 0) 00373 cmin = -1; 00374 } 00375 if(cver_list.size() >= 3) { 00376 cpat = cver_list[2].toInt(&ok); 00377 if(!ok) 00378 continue; 00379 if(cpat < 0) 00380 cpat = -1; 00381 } 00382 if((cmaj >= maj && cmaj <= QT_MAJOR) && 00383 (cmin == -1 || (cmin >= min && cmin <= QT_MINOR)) && 00384 (cpat == -1 || (cpat >= pat && cpat <= QT_PATCH)) && 00385 config->contains(cver + QLatin1Char('/') + key)) { 00386 subKey = cver + QLatin1Char('/'); 00387 maj = cmaj; 00388 min = cmin; 00389 pat = cpat; 00390 } 00391 } 00392 } 00393 } 00394 ret = config->value(subKey + key, defaultValue).toString(); 00395 // expand environment variables in the form $(ENVVAR) 00396 int rep; 00397 QRegExp reg_var(QLatin1String("\\$\\(.*\\)")); 00398 reg_var.setMinimal(true); 00399 while((rep = reg_var.indexIn(ret)) != -1) { 00400 ret.replace(rep, reg_var.matchedLength(), 00401 QString::fromLocal8Bit(qgetenv(ret.mid(rep + 2, 00402 reg_var.matchedLength() - 3).toLatin1().constData()).constData())); 00403 } 00404 config->endGroup(); 00405 } 00406 } 00407 00408 if (QDir::isRelativePath(ret)) { 00409 if (loc == PrefixPath) { 00410 // we make the prefix path absolute to the executable's directory 00411 #ifdef QT_BUILD_QMAKE 00412 return QFileInfo(qmake_libraryInfoFile()).absolutePath(); 00413 #else 00414 if (QCoreApplication::instance()) { 00415 #ifdef Q_OS_MAC 00416 CFBundleRef bundleRef = CFBundleGetMainBundle(); 00417 if (bundleRef) { 00418 QCFType<CFURLRef> urlRef = CFBundleCopyBundleURL(bundleRef); 00419 if (urlRef) { 00420 QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle); 00421 return QDir::cleanPath(path + QLatin1String("/Contents")); 00422 } 00423 } 00424 #endif 00425 return QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(ret); 00426 } else { 00427 return QDir::current().absoluteFilePath(ret); 00428 } 00429 #endif 00430 } else { 00431 // we make any other path absolute to the prefix directory 00432 return QDir(location(PrefixPath)).absoluteFilePath(ret); 00433 } 00434 } 00435 return ret; 00436 }
Here is the call graph for this function:

1.5.1