📄 qglobal.cpp
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qplatformdefs.h"#include "qasciidict.h"#include <limits.h>#include <stdio.h>#include <limits.h>#include <stdarg.h>#include <stdlib.h>#if defined(Q_CC_MSVC) && !defined(Q_OS_TEMP)#include <crtdbg.h>#endif/*! \relates QApplication Returns the Qt version number as a string, for example, "2.3.0" or "3.0.5". The \c QT_VERSION define has the numeric value in the form: 0xmmiibb (m = major, i = minor, b = bugfix). For example, Qt 3.0.5's \c QT_VERSION is 0x030005.*/const char *qVersion(){ return QT_VERSION_STR;}bool qSharedBuild(){#ifdef QT_SHARED return TRUE;#else return FALSE;#endif}/***************************************************************************** System detection routines *****************************************************************************/static bool si_alreadyDone = FALSE;static int si_wordSize;static bool si_bigEndian;/*! \relates QApplication Obtains information about the system. The system's word size in bits (typically 32) is returned in \a *wordSize. The \a *bigEndian is set to TRUE if this is a big-endian machine, or to FALSE if this is a little-endian machine. In debug mode, this function calls qFatal() with a message if the computer is truly weird (i.e. different endianness for 16 bit and 32 bit integers); in release mode it returns FALSE.*/bool qSysInfo( int *wordSize, bool *bigEndian ){#if defined(QT_CHECK_NULL) Q_ASSERT( wordSize != 0 ); Q_ASSERT( bigEndian != 0 );#endif if ( si_alreadyDone ) { // run it only once *wordSize = si_wordSize; *bigEndian = si_bigEndian; return TRUE; } si_wordSize = 0; Q_ULONG n = (Q_ULONG)(~0); while ( n ) { // detect word size si_wordSize++; n /= 2; } *wordSize = si_wordSize; if ( *wordSize != 64 && *wordSize != 32 && *wordSize != 16 ) { // word size: 16, 32 or 64#if defined(QT_CHECK_RANGE) qFatal( "qSysInfo: Unsupported system word size %d", *wordSize );#endif return FALSE; } if ( sizeof(Q_INT8) != 1 || sizeof(Q_INT16) != 2 || sizeof(Q_INT32) != 4 || sizeof(Q_ULONG)*8 != si_wordSize || sizeof(float) != 4 || sizeof(double) != 8 ) {#if defined(QT_CHECK_RANGE) qFatal( "qSysInfo: Unsupported system data type size" );#endif return FALSE; } bool be16, be32; // determine byte ordering short ns = 0x1234; int nl = 0x12345678; unsigned char *p = (unsigned char *)(&ns); // 16-bit integer be16 = *p == 0x12; p = (unsigned char *)(&nl); // 32-bit integer if ( p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78 ) be32 = TRUE; else if ( p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12 ) be32 = FALSE; else be32 = !be16; if ( be16 != be32 ) { // strange machine!#if defined(QT_CHECK_RANGE) qFatal( "qSysInfo: Inconsistent system byte order" );#endif return FALSE; } *bigEndian = si_bigEndian = be32; si_alreadyDone = TRUE; return TRUE;}#if !defined(QWS) && defined(Q_OS_MAC)#include "qt_mac.h"int qMacVersion(){ static int macver = Qt::MV_Unknown; static bool first = TRUE; if(first) { first = FALSE; long gestalt_version; if(Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) { if(gestalt_version >= 0x1030 && gestalt_version < 0x1040) macver = Qt::MV_10_DOT_3; else if(gestalt_version >= 0x1020 && gestalt_version < 0x1030) macver = Qt::MV_10_DOT_2; else if(gestalt_version >= 0x1010 && gestalt_version < 0x1020) macver = Qt::MV_10_DOT_1; else if(gestalt_version >= 0x1000 && gestalt_version < 0x1010) macver = Qt::MV_10_DOT_0; } } return macver;}Qt::MacintoshVersion qt_macver = (Qt::MacintoshVersion)qMacVersion();#elif defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)bool qt_winunicode;#include "qt_windows.h"int qWinVersion(){#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 static int winver = Qt::WV_NT; static int t=0; if ( !t ) { t=1;#ifdef Q_OS_TEMP OSVERSIONINFOW osver; osver.dwOSVersionInfoSize = sizeof(osver); GetVersionEx( &osver );#else OSVERSIONINFOA osver; osver.dwOSVersionInfoSize = sizeof(osver); GetVersionExA( &osver );#endif switch ( osver.dwPlatformId ) { case VER_PLATFORM_WIN32s: winver = Qt::WV_32s; break; case VER_PLATFORM_WIN32_WINDOWS: // We treat Windows Me (minor 90) the same as Windows 98 if ( ( osver.dwMinorVersion == 10 ) || ( osver.dwMinorVersion == 90 ) ) winver = Qt::WV_98; else winver = Qt::WV_95; break; default: // VER_PLATFORM_WIN32_NT if ( osver.dwMajorVersion < 5 ) { winver = Qt::WV_NT; } else if ( osver.dwMinorVersion == 0 ) { winver = Qt::WV_2000; } else { winver = Qt::WV_XP; } } }#if defined(UNICODE) if ( winver & Qt::WV_NT_based ) qt_winunicode = TRUE; else#endif qt_winunicode = FALSE; return winver;}Qt::WindowsVersion qt_winver = (Qt::WindowsVersion)qWinVersion();#endif/***************************************************************************** Debug output routines *****************************************************************************//*! \fn void qDebug( const char *msg, ... ) \relates QApplication Prints a debug message \a msg, or calls the message handler (if it has been installed). This function takes a format string and a list of arguments, similar to the C printf() function. Example: \code qDebug( "my window handle = %x", myWidget->id() ); \endcode Under X11, the text is printed to stderr. Under Windows, the text is sent to the debugger. \warning The internal buffer is limited to 8196 bytes (including the '\0'-terminator). \warning Passing (const char *)0 as argument to qDebug might lead to crashes on certain platforms due to the platforms printf implementation. \sa qWarning(), qFatal(), qInstallMsgHandler(), \link debug.html Debugging\endlink*//*! \fn void qWarning( const char *msg, ... ) \relates QApplication Prints a warning message \a msg, or calls the message handler (if it has been installed). This function takes a format string and a list of arguments, similar to the C printf() function. Example: \code void f( int c ) { if ( c > 200 ) qWarning( "f: bad argument, c == %d", c ); } \endcode Under X11, the text is printed to stderr. Under Windows, the text is sent to the debugger. \warning The internal buffer is limited to 8196 bytes (including the '\0'-terminator). \warning Passing (const char *)0 as argument to qWarning might lead to crashes on certain platforms due to the platforms printf implementation. \sa qDebug(), qFatal(), qInstallMsgHandler(), \link debug.html Debugging\endlink*//*! \fn void qFatal( const char *msg, ... ) \relates QApplication Prints a fatal error message \a msg and exits, or calls the message handler (if it has been installed). This function takes a format string and a list of arguments, similar to the C printf() function. Example: \code int divide( int a, int b ) { if ( b == 0 ) // program error qFatal( "divide: cannot divide by zero" ); return a/b; } \endcode Under X11, the text is printed to stderr. Under Windows, the text is sent to the debugger. \warning The internal buffer is limited to 8196 bytes (including the '\0'-terminator). \warning Passing (const char *)0 as argument to qFatal might lead to crashes on certain platforms due to the platforms printf implementation. \sa qDebug(), qWarning(), qInstallMsgHandler(), \link debug.html Debugging\endlink*/static QtMsgHandler handler = 0; // pointer to debug handlerstatic const int QT_BUFFER_LENGTH = 8196; // internal buffer length#ifdef Q_OS_MACQString cfstring2qstring(CFStringRef str){ if(!str) return QString(); CFIndex length = CFStringGetLength(str); if(const UniChar *chars = CFStringGetCharactersPtr(str)) return QString((QChar *)chars, length); UniChar *buffer = (UniChar*)malloc(length * sizeof(UniChar)); CFStringGetCharacters(str, CFRangeMake(0, length), buffer); QString ret((QChar *)buffer, length); free(buffer); return ret;}#if 0unsigned char * p_str(const char * c, int len=-1){ const int maxlen = 255; if(len == -1) len = qstrlen(c); if(len > maxlen) { qWarning( "p_str len must never exceed %d", maxlen ); len = maxlen; } unsigned char *ret = (unsigned char*)malloc(len+2); *ret=len; memcpy(((char *)ret)+1,c,len); *(ret+len+1) = '\0'; return ret;}unsigned char * p_str(const QString &s){ return p_str(s, s.length());}QCString p2qstring(const unsigned char *c) { char *arr = (char *)malloc(c[0] + 1); memcpy(arr, c+1, c[0]); arr[c[0]] = '\0'; QCString ret = arr; delete arr; return ret;}#endif#endif#ifdef Q_CC_MWERKS#include "qt_mac.h"extern bool qt_is_gui_used;static void mac_default_handler( const char *msg ){ if ( qt_is_gui_used ) { const char *p = p_str(msg); DebugStr(p); free(p); } else { fprintf( stderr, msg ); }}#endifvoid qDebug( const char *msg, ... ){ char buf[QT_BUFFER_LENGTH]; va_list ap; va_start( ap, msg ); // use variable arg list if ( handler ) {#if defined(QT_VSNPRINTF) QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap );#else vsprintf( buf, msg, ap );#endif va_end( ap ); (*handler)( QtDebugMsg, buf ); } else {#if defined(Q_CC_MWERKS) vsprintf( buf, msg, ap ); // ### is there no vsnprintf()? va_end( ap ); mac_default_handler(buf);#else vfprintf( stderr, msg, ap ); va_end( ap ); fprintf( stderr, "\n" ); // add newline#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -