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

📄 qglobal.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }}// copied... this looks really bad.void debug( 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 {#ifdef 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    }}void qWarning( 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)( QtWarningMsg, buf );    } else {#ifdef 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    }}// again, copiedvoid warning( 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)( QtWarningMsg, buf );    } else {#ifdef 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    }}void qFatal( 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)( QtFatalMsg, buf );    } else {#ifdef Q_CC_MWERKS	vsprintf( buf, msg, ap );		// ### is there no vsnprintf()?	va_end( ap );        mac_default_handler(buf);#else	vsprintf( buf, msg, ap );	va_end( ap );	fprintf( stderr, "%s\n", buf );		// add newline#endif#if defined(Q_OS_UNIX) && defined(QT_DEBUG)	abort();				// trap; generates core dump#elif defined(Q_OS_TEMP) && defined(_DEBUG)	QString fstr;	fstr.sprintf( "%s:%s %s %s", __FILE__, __LINE__, QT_VERSION_STR, buf );	OutputDebugString( fstr.ucs2() );#elif defined(Q_CC_MSVC) && defined(_DEBUG)	_CrtDbgReport( _CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, buf );#else	exit( 1 );				// goodbye cruel world#endif    }}// yet again, copiedvoid fatal( 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)( QtFatalMsg, buf );    } else {#ifdef 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#if defined(Q_OS_UNIX) && defined(QT_DEBUG)	abort();				// trap; generates core dump#elif defined(Q_OS_TEMP) && defined(_DEBUG)	QString fstr;	fstr.sprintf( "%s:%s %s %s", __FILE__, __LINE__, QT_VERSION_STR, buf );	OutputDebugString( fstr.ucs2() );#elif defined(Q_CC_MSVC) && defined(_DEBUG)	_CrtDbgReport( _CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, buf );#else	exit( 1 );				// goodbye cruel world#endif    }}/*!  \relates QApplication  Prints the message \a msg and uses \a code to get a system specific  error message. When \a code is -1 (the default), the system's last  error code will be used if possible. Use this method to handle  failures in platform specific API calls.  This function does nothing when Qt is built with \c QT_NO_DEBUG  defined.*/void qSystemWarning( const char* msg, int code ){#ifndef QT_NO_DEBUG#if defined(Q_OS_WIN32)    if ( code == -1 )	code = GetLastError();    if ( !code )	return;    unsigned short *string;    QT_WA( {	FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,		       NULL,		       code,		       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),		       (LPTSTR)&string,		       0,		       NULL );	qWarning( "%s\n\tError code %d - %s", msg, code, QString::fromUcs2(string).latin1() );    }, {	FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,			NULL,			code,			MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),			(char*)&string,			0,			NULL );	qWarning( "%s\n\tError code %d - %s", msg, code, (const char*)string );    } );    LocalFree( (HLOCAL)string );#else    if ( code != -1 )	qWarning( "%s\n\tError code %d - %s", msg, code, strerror( code ) );    else	qWarning( msg );#endif#else    Q_UNUSED( msg );    Q_UNUSED( code );#endif}/*!    \fn void Q_ASSERT( bool test )    \relates QApplication    Prints a warning message containing the source code file name and    line number if \a test is FALSE.    This is really a macro defined in \c qglobal.h.    Q_ASSERT is useful for testing pre- and post-conditions.    Example:    \code	//	// File: div.cpp	//	#include <qglobal.h>	int divide( int a, int b )	{	    Q_ASSERT( b != 0 );			// this is line 9	    return a/b;	}    \endcode    If \c b is zero, the Q_ASSERT statement will output the following    message using the qWarning() function:    \code	ASSERT: "b == 0" in div.cpp (9)    \endcode    \sa qWarning(), \link debug.html Debugging\endlink*//*!    \fn void Q_CHECK_PTR( void *p )    \relates QApplication    If \a p is 0, prints a warning message containing the source code file    name and line number, saying that the program ran out of memory.    This is really a macro defined in \c qglobal.h.    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(), \link debug.html Debugging\endlink*///// The Q_CHECK_PTR macro calls this function to check if an allocation went ok.//#if (QT_VERSION-0 >= 0x040000)#if defined(Q_CC_GNU)#warning "Change Q_CHECK_PTR to '{if ((p)==0) qt_check_pointer(__FILE__,__LINE__);}'"#warning "No need for qt_check_pointer() to return a value - make it void!"#endif#endifbool qt_check_pointer( bool c, const char *n, int l ){    if ( c )	qWarning( "In file %s, line %d: Out of memory", n, l );    return TRUE;}static bool firstObsoleteWarning(const char *obj, const char *oldfunc ){    static QAsciiDict<int> *obsoleteDict = 0;    if ( !obsoleteDict ) {			// first time func is called	obsoleteDict = new QAsciiDict<int>;#if defined(QT_DEBUG)	qDebug(      "You are using obsolete functions in the Qt library. Call the function\n"      "qSuppressObsoleteWarnings() to suppress obsolete warnings.\n"	     );#endif    }    QCString s( obj );    s += "::";    s += oldfunc;    if ( obsoleteDict->find(s.data()) == 0 ) {	obsoleteDict->insert( s.data(), (int*)1 );	// anything different from 0	return TRUE;    }    return FALSE;}static bool suppressObsolete = FALSE;void qSuppressObsoleteWarnings( bool suppress ){    suppressObsolete = suppress;}void qObsolete(	 const char *obj, const char *oldfunc, const char *newfunc ){    if ( suppressObsolete )	return;    if ( !firstObsoleteWarning(obj, oldfunc) )	return;    if ( obj )	qDebug( "%s::%s: This function is obsolete, use %s instead.",	       obj, oldfunc, newfunc );    else	qDebug( "%s: This function is obsolete, use %s instead.",	       oldfunc, newfunc );}void qObsolete(	 const char *obj, const char *oldfunc ){    if ( suppressObsolete )	return;    if ( !firstObsoleteWarning(obj, oldfunc) )	return;    if ( obj )	qDebug( "%s::%s: This function is obsolete.", obj, oldfunc );    else	qDebug( "%s: This function is obsolete.", oldfunc );}void qObsolete(	 const char *message ){    if ( suppressObsolete )	return;    if ( !firstObsoleteWarning( "Qt", message) )	return;    qDebug( "%s", message );}/*!    \relates QApplication    Installs a Qt message handler \a h. Returns a pointer to the    message handler previously defined.    The message handler is a function that prints out debug messages,    warnings 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 );		    break;		case QtWarningMsg:		    fprintf( stderr, "Warning: %s\n", msg );		    break;		case QtFatalMsg:		    fprintf( stderr, "Fatal: %s\n", msg );		    abort();			// deliberately core dump	    }	}	int main( int argc, char **argv )	{	    qInstallMsgHandler( myMessageOutput );	    QApplication a( argc, argv );	    ...	    return a.exec();	}    \endcode    \sa qDebug(), qWarning(), qFatal(), \link debug.html Debugging\endlink*/QtMsgHandler qInstallMsgHandler( QtMsgHandler h ){    QtMsgHandler old = handler;    handler = h;    return old;}/*    Dijkstra's bisection algorithm to find the square root as an integer.    Deliberately not exported as part of the Qt API, but used in both    qsimplerichtext.cpp and qgfxraster_qws.cpp*/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;}

⌨️ 快捷键说明

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