⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlibrary.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    QStringList suffixes = completeSuffix.split(QLatin1Char('.'));    QString suffix = suffixes.first();# if defined(Q_OS_DARWIN)        // On Mac, libs look like libmylib.1.0.0.dylib    const QString lastSuffix = suffixes.at(suffixes.count() - 1);    const QString firstSuffix = suffixes.at(0);            bool valid = (lastSuffix == "dylib"            || firstSuffix == "so"            || firstSuffix == "bundle");    return valid;# elif defined(Q_OS_HPUX)/*      See "HP-UX Linker and Libraries User's Guide", section "Link-time Differences between PA-RISC and IPF":    "In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit),     the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix." */    bool valid = (suffix == "sl");#  if defined __ia64    valid |= (suffix == "so")#  endif# elif defined(Q_OS_UNIX)    bool valid = (suffix == "so");# elif defined(Q_OS_AIX)	bool valid = (suffix == "a"			|| suffix == "so");# else    bool valid = false;# endif    for (int i = 1; i < suffixes.count() && valid; ++i)        suffixes.at(i).toInt(&valid);    return valid;#endif}bool QLibraryPrivate::isPlugin(){    if (pluginState != MightBeAPlugin)        return pluginState == IsAPlugin;    if (!QLibrary::isLibrary(fileName))        return false;    bool debug = !QLIBRARY_AS_DEBUG;    QByteArray key;    bool success = false;    QFileInfo fileinfo(fileName);#ifndef QT_NO_DATESTRING    lastModified  = fileinfo.lastModified().toString(Qt::ISODate);#endif    QString regkey = QString::fromLatin1("Qt Plugin Cache %1.%2.%3/%4")                     .arg((QT_VERSION & 0xff0000) >> 16)                     .arg((QT_VERSION & 0xff00) >> 8)                     .arg(QLIBRARY_AS_DEBUG ? "debug" : "false")                     .arg(fileName);    QStringList reg;    QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));    reg = settings.value(regkey).toStringList();    if (reg.count() == 4 && lastModified == reg.at(3)) {        qt_version = reg.at(0).toUInt(0, 16);        debug = bool(reg.at(1).toInt());        key = reg.at(2).toLatin1();        success = qt_version != 0;    } else {#if defined(Q_OS_UNIX)        if (!pHnd) {            // use unix shortcut to avoid loading the library            success = qt_unix_query(fileName, &qt_version, &debug, &key);        } else#endif        {            bool temporary_load = false;            if (!pHnd)                temporary_load =  load_sys();#  ifdef Q_CC_BOR            typedef const char * __stdcall (*QtPluginQueryVerificationDataFunction)();#  else            typedef const char * (*QtPluginQueryVerificationDataFunction)();#  endif            QtPluginQueryVerificationDataFunction qtPluginQueryVerificationDataFunction =                (QtPluginQueryVerificationDataFunction) resolve("qt_plugin_query_verification_data");            if (!qtPluginQueryVerificationDataFunction                || !qt_parse_pattern(qtPluginQueryVerificationDataFunction(), &qt_version, &debug, &key)) {                qt_version = 0;                key = "unknown";                if (temporary_load)                    unload_sys();            } else {                success = true;            }        }        QStringList queried;        queried << QString::number(qt_version,16)                << QString::number((int)debug)                << QLatin1String(key)                << lastModified;        settings.setValue(regkey, queried);    }    if (!success)        return false;    pluginState = IsNotAPlugin; // be pessimistic    if ((qt_version > QT_VERSION) || ((QT_VERSION & 0xff0000) > (qt_version & 0xff0000))) {#if defined(QT_DEBUG_COMPONENT)        qWarning("In %s:\n"                 "  Plugin uses incompatible Qt library (%d.%d.%d) [%s]",                 (const char*) QFile::encodeName(fileName),                 (qt_version&0xff0000) >> 16, (qt_version&0xff00) >> 8, qt_version&0xff,                 debug ? "debug" : "release");#endif    } else if (key != QT_BUILD_KEY) {#if defined(QT_DEBUG_COMPONENT)        qWarning("In %s:\n"                 "  Plugin uses incompatible Qt library\n"                 "  expected build key \"%s\", got \"%s\"",                 (const char*) QFile::encodeName(fileName),                 QT_BUILD_KEY,                 key.isEmpty() ? "<null>" : (const char *) key);#endif#ifndef QT_NO_DEBUG_PLUGIN_CHECK    } else if(debug != QLIBRARY_AS_DEBUG) {        //don't issue a qWarning since we will hopefully find a non-debug? --Sam#endif    } else {        pluginState = IsAPlugin;    }    return pluginState == IsAPlugin;}/*!    Loads the library and returns true if the library was loaded    successfully; otherwise returns false. Since resolve() always    calls this function before resolving any symbols it is not    necessary to call it explicitly. In some situations you might want    the library loaded in advance, in which case you would use this    function.    On Mac OS X this function uses code from dlcompat, part of the    OpenDarwin project.    \sa unload()    \legalese    Copyright (c) 2002 Jorge Acereda and Peter O'Gorman.    Permission is hereby granted, free of charge, to any person obtaining    a copy of this software and associated documentation files (the    "Software"), to deal in the Software without restriction, including    without limitation the rights to use, copy, modify, merge, publish,    distribute, sublicense, and/or sell copies of the Software, and to    permit persons to whom the Software is furnished to do so, subject to    the following conditions:    The above copyright notice and this permission notice shall be    included in all copies or substantial portions of the Software.    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/bool QLibrary::load(){    if (!d)        return false;    if (did_load)        return d->pHnd;    did_load = true;    return d->load();}/*!    Unloads the library and returns true if the library could be    unloaded; otherwise returns false.    This happens automatically on application termination, so you    shouldn't normally need to call this function.    If other instances of QLibrary are using the same library, the    call will fail, and unloading will only happen when every instance    has called unload().    Note that on Mac OS X, dynamic libraries cannot be unloaded.    \sa resolve(), load()*/bool QLibrary::unload(){    if (did_load) {        did_load = false;        return d->unload();    }    return false;}/*!    Returns true if the library is loaded; otherwise returns false.    \sa load() */bool QLibrary::isLoaded() const{    return d && d->pHnd;}/*!    Constructs a library with the given \a parent. */QLibrary::QLibrary(QObject *parent)    :QObject(parent), d(0), did_load(false){}/*!    Constructs a library object with the given \a parent that will    load the library specified by \a fileName.    We recommend omitting the file's suffix in \a fileName, since    QLibrary will automatically look for the file with the appropriate    suffix in accordance with the platform, e.g. ".so" on Unix,    ".dylib" on Mac OS X, and ".dll" on Windows. (See \l{fileName}.) */QLibrary::QLibrary(const QString& fileName, QObject *parent)    :QObject(parent), d(0), did_load(false){    setFileName(fileName);}/*!    Constructs a library object with the given \a parent that will    load the library specified by \a fileName and major version number \a verNum.    We recommend omitting the file's suffix in \a fileName, since    QLibrary will automatically look for the file with the appropriate    suffix in accordance with the platform, e.g. ".so" on Unix,    ".dylib" on Mac OS X, and ".dll" on Windows. (See \l{fileName}.) */QLibrary::QLibrary(const QString& fileName, int verNum, QObject *parent)    :QObject(parent), d(0), did_load(false){    setFileNameAndVersion(fileName, verNum);}/*!    Destroys the QLibrary object.    Unless unload() was called explicitly, the library stays in memory    until the application terminates.    \sa isLoaded(), unload()*/QLibrary::~QLibrary(){    if (d)        d->release();}/*!    \property QLibrary::fileName    \brief the file name of the library    We recommend omitting the file's suffix in the file name, since    QLibrary will automatically look for the file with the appropriate    suffix (see isLibrary()).    When loading the library, QLibrary searches in all system-specific    library locations (e.g. \c LD_LIBRARY_PATH on Unix), unless the    file name has an absolute path. After loading the library    successfully, fileName() returns the fully qualified file name of    the library. For example, after successfully loading the "GL"    library on unix, fileName() will return "libGL.so".*/void QLibrary::setFileName(const QString &fileName){    if (d) {        d->release();        d = 0;        did_load = false;    }    d = QLibraryPrivate::findOrCreate(fileName);    if (d && d->pHnd)        did_load = true;}QString QLibrary::fileName() const{    if (d)        return d->qualifiedFileName.isEmpty() ? d->fileName : d->qualifiedFileName;    return QString();}/*!    \fn void QLibrary::setFileNameAndVersion(const QString &fileName, int versionNumber)    Sets the fileName property and major version number to \a fileName    and \a versionNumber respectively.    \sa setFileName()*/void QLibrary::setFileNameAndVersion(const QString &fileName, int verNum){    if (d) {        d->release();        d = 0;        did_load = false;    }    d = QLibraryPrivate::findOrCreate(fileName, verNum);    if (d && d->pHnd)        did_load = true;}/*!    Returns the address of the exported symbol \a symbol. The library is    loaded if necessary. The function returns 0 if the symbol could    not be resolved or if the library could not be loaded.    Example:    \code        typedef int (*AvgFunction)(int, int);        AvgFunction avg = (AvgFunction) library->resolve("avg");        if (avg)            return avg(5, 8);        else            return -1;    \endcode    The symbol must be exported as a C function from the library. This    means that the function must be wrapped in an \c{extern "C"} if    the library is compiled with a C++ compiler. On Windows you must    also explicitly export the function from the DLL using the    \c{__declspec(dllexport)} compiler directive, for example:    \code        extern "C" MY_EXPORT int avg(int a, int b)        {            return (a + b) / 2;        }    \endcode    with \c MY_EXPORT defined as    \code        #ifdef Q_WS_WIN        #define MY_EXPORT __declspec(dllexport)        #else        #define MY_EXPORT        #endif    \endcode    On Mac OS X this function uses code from dlcompat, part of the    OpenDarwin project.    \legalese    Copyright (c) 2002 Jorge Acereda and Peter O'Gorman.    Permission is hereby granted, free of charge, to any person obtaining    a copy of this software and associated documentation files (the    "Software"), to deal in the Software without restriction, including    without limitation the rights to use, copy, modify, merge, publish,    distribute, sublicense, and/or sell copies of the Software, and to    permit persons to whom the Software is furnished to do so, subject to    the following conditions:    The above copyright notice and this permission notice shall be    included in all copies or substantial portions of the Software.    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/void *QLibrary::resolve(const char *symbol){    if (!d)        return 0;    if (!d->pHnd)        d->load();    return d->resolve(symbol);}/*!    \overload    Loads the library \a fileName and returns the address of the    exported symbol \a symbol. Note that \a fileName should not    include the platform-specific file suffix; (see \l{fileName}). The    library remains loaded until the application exits.    The function returns 0 if the symbol could not be resolved or if    the library could not be loaded.    \sa resolve()*/void *QLibrary::resolve(const QString &fileName, const char *symbol){    QLibrary library(fileName);    return library.resolve(symbol);}/*!    \overload    Loads the library \a fileName with major version number \a verNum and    returns the address of the exported symbol \a symbol.    Note that \a fileName should not include the platform-specific file suffix;    (see \l{fileName}). The library remains loaded until the application exits.    The function returns 0 if the symbol could not be resolved or if    the library could not be loaded.    \sa resolve()*/void *QLibrary::resolve(const QString &fileName, int verNum, const char *symbol){    QLibrary library(fileName, verNum);    return library.resolve(symbol);}/*!    \fn QString QLibrary::library() const    Use fileName() instead.*//*!    \fn void QLibrary::setAutoUnload( bool b )    Use load(), isLoaded(), and unload() as necessary instead.*/#endif // QT_NO_LIBRARY

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -