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

📄 qglobal.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    Defined if the application is compiled using KAI C++.*//*!    \macro Q_CC_INTEL    \relates <QtGlobal>    Defined if the application is compiled using Intel C++ for Linux,    Intel C++ for Windows.*//*!    \macro Q_CC_HIGHC    \relates <QtGlobal>    Defined if the application is compiled using MetaWare High C/C++.*//*!    \macro Q_CC_PGI    \relates <QtGlobal>    Defined if the application is compiled using Portland Group C++.*//*!    \macro Q_CC_GHS    \relates <QtGlobal>    Defined if the application is compiled using Green Hills    Optimizing C++ Compilers.*/#if defined(QT_BUILD_QMAKE)// needed to bootstrap qmakestatic const unsigned int qt_one = 1;const int QSysInfo::ByteOrder = ((*((unsigned char *) &qt_one) == 0) ? BigEndian : LittleEndian);#endif#if !defined(QWS) && defined(Q_OS_MAC)#include "private/qcore_mac_p.h"#include "qnamespace.h"Q_CORE_EXPORT OSErr qt_mac_create_fsref(const QString &file, FSRef *fsref){    return FSPathMakeRef(reinterpret_cast<const UInt8 *>(file.toUtf8().constData()), fsref, 0);}// Don't use this function, it won't work in 10.5 (Leopard) and upQ_CORE_EXPORT OSErr qt_mac_create_fsspec(const QString &file, FSSpec *spec){    FSRef fsref;    OSErr ret = qt_mac_create_fsref(file, &fsref);    if (ret == noErr)        ret = FSGetCatalogInfo(&fsref, kFSCatInfoNone, 0, 0, spec, 0);    return ret;}Q_CORE_EXPORT void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1){    if(len == -1)        len = s.length();#if 0    UnicodeMapping mapping;    mapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault,                                                 kTextEncodingDefaultVariant,                                                 kUnicode16BitFormat);    mapping.otherEncoding = (encoding ? encoding : );    mapping.mappingVersion = kUnicodeUseLatestMapping;    UnicodeToTextInfo info;    OSStatus err = CreateUnicodeToTextInfo(&mapping, &info);    if(err != noErr) {        qDebug("Qt: internal: Unable to create pascal string '%s'::%d [%ld]",               s.left(len).latin1(), (int)encoding, err);        return;    }    const int unilen = len * 2;    const UniChar *unibuf = (UniChar *)s.unicode();    ConvertFromUnicodeToPString(info, unilen, unibuf, str);    DisposeUnicodeToTextInfo(&info);#else    Q_UNUSED(encoding);    CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());#endif}Q_CORE_EXPORT QString qt_mac_from_pascal_string(const Str255 pstr) {    return QCFString(CFStringCreateWithPascalString(0, pstr, CFStringGetSystemEncoding()));}static QSysInfo::MacVersion macVersion(){    SInt32 gestalt_version;    if (Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) {        return QSysInfo::MacVersion(((gestalt_version & 0x00F0) >> 4) + 2);    }    return QSysInfo::MV_Unknown;}const QSysInfo::MacVersion QSysInfo::MacintoshVersion = macVersion();#elif defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) || defined(Q_OS_TEMP)#include "qt_windows.h"static QSysInfo::WinVersion winVersion(){#ifndef VER_PLATFORM_WIN32s#define VER_PLATFORM_WIN32s            0#endif#ifndef VER_PLATFORM_WIN32_WINDOWS#define VER_PLATFORM_WIN32_WINDOWS  1#endif#ifndef VER_PLATFORM_WIN32_NT#define VER_PLATFORM_WIN32_NT            2#endif#ifndef VER_PLATFORM_WIN32_CE#define VER_PLATFORM_WIN32_CE            3#endif    static QSysInfo::WinVersion winver = QSysInfo::WV_NT;#ifndef Q_OS_TEMP    OSVERSIONINFOA osver;    osver.dwOSVersionInfoSize = sizeof(osver);    GetVersionExA(&osver);#else    DWORD qt_cever = 0;    OSVERSIONINFOW osver;    osver.dwOSVersionInfoSize = sizeof(osver);    GetVersionEx(&osver);    qt_cever = osver.dwMajorVersion * 100;    qt_cever += osver.dwMinorVersion * 10;#endif    switch (osver.dwPlatformId) {    case VER_PLATFORM_WIN32s:        winver = QSysInfo::WV_32s;        break;    case VER_PLATFORM_WIN32_WINDOWS:        // We treat Windows Me (minor 90) the same as Windows 98        if (osver.dwMinorVersion == 90)            winver = QSysInfo::WV_Me;        else if (osver.dwMinorVersion == 10)            winver = QSysInfo::WV_98;        else            winver = QSysInfo::WV_95;        break;#ifdef Q_OS_TEMP    case VER_PLATFORM_WIN32_CE:#ifdef Q_OS_TEMP        if (qt_cever >= 400)            winver = QSysInfo::WV_CENET;        else#endif            winver = QSysInfo::WV_CE;        break;#endif    default: // VER_PLATFORM_WIN32_NT        if (osver.dwMajorVersion < 5) {            winver = QSysInfo::WV_NT;        } else if (osver.dwMajorVersion == 6) {            winver = QSysInfo::WV_VISTA;        } else if (osver.dwMinorVersion == 0) {            winver = QSysInfo::WV_2000;        } else if (osver.dwMinorVersion == 1) {            winver = QSysInfo::WV_XP;        } else if (osver.dwMinorVersion == 2) {            winver = QSysInfo::WV_2003;        } else {            qWarning("Qt: Untested Windows version detected!");            winver = QSysInfo::WV_NT_based;        }    }#ifdef QT_DEBUG    {        QByteArray override = qgetenv("QT_WINVER_OVERRIDE");        if (override.isEmpty())            return winver;        if (override == "Me")            winver = QSysInfo::WV_Me;        if (override == "95")            winver = QSysInfo::WV_95;        else if (override == "98")            winver = QSysInfo::WV_98;        else if (override == "NT")            winver = QSysInfo::WV_NT;        else if (override == "2000")            winver = QSysInfo::WV_2000;        else if (override == "2003")            winver = QSysInfo::WV_2003;        else if (override == "XP")            winver = QSysInfo::WV_XP;        else if (override == "VISTA")            winver = QSysInfo::WV_VISTA;    }#endif    return winver;}const QSysInfo::WinVersion QSysInfo::WindowsVersion = winVersion();#endif/*!    \macro void Q_ASSERT(bool test)    \relates <QtGlobal>    Prints a warning message containing the source code file name and    line number if \a test is false.    Q_ASSERT() is useful for testing pre- and post-conditions    during development. It does nothing if \c QT_NO_DEBUG was defined    during compilation.    Example:    \code        // File: div.cpp        #include <QtGlobal>        int divide(int a, int b)        {            Q_ASSERT(b != 0);            return a / b;        }    \endcode    If \c b is zero, the Q_ASSERT statement will output the following    message using the qFatal() function:    \code        ASSERT: "b == 0" in file div.cpp, line 7    \endcode    \sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}*//*!    \macro void Q_ASSERT_X(bool test, const char *where, const char *what)    \relates <QtGlobal>    Prints the message \a what together with the location \a where,    the source file name and line number if \a test is false.    Q_ASSERT_X is useful for testing pre- and post-conditions during    development. It does nothing if \c QT_NO_DEBUG was defined during    compilation.    Example:    \code        // File: div.cpp        #include <QtGlobal>        int divide(int a, int b)        {            Q_ASSERT_X(b != 0, "divide", "division by zero");            return a / b;        }    \endcode    If \c b is zero, the Q_ASSERT_X statement will output the following    message using the qFatal() function:    \code        ASSERT failure in divide: "division by zero", file div.cpp, line 7    \endcode    \sa Q_ASSERT(), qFatal(), {Debugging Techniques}*//*!    \macro void Q_CHECK_PTR(void *pointer)    \relates <QtGlobal>    If \a pointer is 0, prints a warning message containing the source    code's file name and line number, saying that the program ran out    of memory.    Q_CHECK_PTR does nothing if \c QT_NO_DEBUG was defined during    compilation.    Example:    \code        int *a;        Q_CHECK_PTR(a = new int[80]);   // WRONG!        a = new (nothrow) int[80];      // Right        Q_CHECK_PTR(a);    \endcode    \sa qWarning(), {Debugging Techniques}*//*!    \macro const char* Q_FUNC_INFO()    \relates <QtGlobal>    Expands to a string that describe the function the macro resides in. How this string looks    more specifically is compiler dependent. With GNU GCC it is typically the function signature,    while with other compilers it might be the line and column number.    Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:    \code        template<typename TInputType>        const TInputType &myMin(const TInputType &value1, const TInputType &value2)        {            qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2;            if(value1 < value2)                return value1;            else                return value2;        }    \endcode    when instantiated with the integer type, will with the GCC compiler produce:    \tt{const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4}    If this macro is used outside a function, the behavior is undefined. *//*  The Q_CHECK_PTR macro calls this function if an allocation check  fails.*/void qt_check_pointer(const char *n, int l){    qWarning("In file %s, line %d: Out of memory", n, l);}/*  The Q_ASSERT macro calls this this function when the test fails.*/void qt_assert(const char *assertion, const char *file, int line){    qFatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);}/*  The Q_ASSERT_X macro calls this this function when the test fails.*/void qt_assert_x(const char *where, const char *what, const char *file, int line){    qFatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);}/*    Dijkstra's bisection algorithm to find the square root of an integer.    Deliberately not exported as part of the Qt API, but used in both    qsimplerichtext.cpp and qgfxraster_qws.cpp*/Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n){    // n must be in the range 0...UINT_MAX/2-1    if (n >= (UINT_MAX>>2)) {        unsigned int r = 2 * qt_int_sqrt(n / 4);        unsigned int r2 = r + 1;        return (n >= r2 * r2) ? r2 : r;    }    uint h, p= 0, q= 1, r= n;    while (q <= n)        q <<= 2;    while (q != 1) {        q >>= 2;        h= p + q;        p >>= 1;        if (r >= h) {            p += q;            r -= h;        }    }    return p;}#if defined(qMemCopy)#  undef qMemCopy#endif#if defined(qMemSet)#  undef qMemSet#endifvoid *qMalloc(size_t size) { return ::malloc(size); }void qFree(void *ptr) { ::free(ptr); }void *qRealloc(void *ptr, size_t size) { return ::realloc(ptr, size); }void *qMemCopy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); }void *qMemSet(void *dest, int c, size_t n) { return memset(dest, c, n); }static QtMsgHandler handler = 0;                // pointer to debug handlerstatic const int QT_BUFFER_LENGTH = 8192;       // internal buffer length#ifdef Q_CC_MWERKS#include <CoreServices/CoreServices.h>extern bool qt_is_gui_used;static void mac_default_handler(const char *msg){    if (qt_is_gui_used) {        Str255 pmsg;        qt_mac_to_pascal_string(msg, pmsg);        DebugStr(pmsg);    } else {        fprintf(stderr, msg);    }}#endif // Q_CC_MWERKSQString qt_error_string(int errorCode){    const char *s = 0;    QString ret;    if (errorCode == -1) {#if defined(Q_OS_WIN32)        errorCode = GetLastError();#else        errorCode = errno;#endif    }    switch (errorCode) {    case 0:        break;    case EACCES:        s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");        break;    case EMFILE:        s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");        break;    case ENOENT:        s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");        break;    case ENOSPC:        s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");        break;    default: {#ifdef Q_OS_WIN        QT_WA({            unsigned short *string = 0;            FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,                          NULL,                          errorCode,                          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),                          (LPTSTR)&string,                          0,                          NULL);            ret = QString::fromUtf16(string);            LocalFree((HLOCAL)string);        }, {            char *string = 0;            FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,                           NULL,                           errorCode,                           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),                           (LPSTR)&string,                           0,                           NULL);            ret = QString::fromLocal8Bit(string);            LocalFree((HLOCAL)string);        });#elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY)        QByteArray buf(1024, '\0');        strerror_r(errorCode, buf.data(), buf.size());        ret = QString::fromLocal8Bit(buf.constData());#else        ret = QString::fromLocal8Bit(strerror(errorCode));#endif	break; }    }    if (s)        // ######## this breaks moc build currently//         ret = QCoreApplication::translate("QIODevice", s);        ret = QString::fromLatin1(s);    return ret.trimmed();}/*!    \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler)    \relates <QtGlobal>    Installs a Qt message \a handler which has been defined    previously. Returns a pointer to the message \a handler.    The message handler is a function that prints out debug messages,    warnings, critical and fatal error messages. The Qt library (debug    version) contains hundreds of warning messages that are printed    when internal errors (usually invalid function arguments)    occur. If you implement your own message handler, you get total    control of these messages.    The default message handler prints the message to the standard    output under X11 or to the debugger under Windows. If it is a    fatal message, the application aborts immediately.    Only one message handler can be defined, since this is usually    done on an application-wide basis to control debug output.    To restore the message handler, call \c qInstallMsgHandler(0).    Example:    \code        #include <qapplication.h>        #include <stdio.h>        #include <stdlib.h>        void myMessageOutput(QtMsgType type, const char *msg)        {            switch (type) {            case QtDebugMsg:                fprintf(stderr, "Debug: %s\n", msg);

⌨️ 快捷键说明

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