📄 qglobal.cpp
字号:
fflush( mac_debug ); } fclose(mac_debug); } exit(0);}// copied... this looks really bad.void fatal( const char *msg, ... ){ mac_debug=fopen( "debug.txt", "a+" ); if(mac_debug) { char buf[8196]; va_list ap; va_start( ap, msg ); // use variable arg list if ( handler ) { vsprintf( buf, msg, ap ); va_end( ap ); (*handler)( QtDebugMsg, buf ); } else { vfprintf( mac_debug, msg, ap ); va_end( ap ); fprintf( mac_debug, "\n" ); // add newline fflush( mac_debug ); } fclose(mac_debug); } exit(0);}#elsevoid qDebug( const char *msg, ... ){ char buf[8196]; va_list ap; va_start( ap, msg ); // use variable arg list if ( handler ) { vsprintf( buf, msg, ap ); // ### vsnprintf would be great here va_end( ap ); (*handler)( QtDebugMsg, buf ); } else { vfprintf( stderr, msg, ap ); va_end( ap ); fprintf( stderr, "\n" ); // add newline }}// copied... this looks really bad.void debug( const char *msg, ... ){ char buf[8196]; va_list ap; va_start( ap, msg ); // use variable arg list if ( handler ) { vsprintf( buf, msg, ap ); va_end( ap ); (*handler)( QtDebugMsg, buf ); } else { vfprintf( stderr, msg, ap ); va_end( ap ); fprintf( stderr, "\n" ); // add newline }}void qWarning( const char *msg, ... ){ char buf[8196]; va_list ap; va_start( ap, msg ); // use variable arg list if ( handler ) { vsprintf( buf, msg, ap ); va_end( ap ); (*handler)( QtWarningMsg, buf ); } else { vfprintf( stderr, msg, ap ); va_end( ap ); fprintf( stderr, "\n" ); // add newline }}// again, copiedvoid warning( const char *msg, ... ){ char buf[8196]; va_list ap; va_start( ap, msg ); // use variable arg list if ( handler ) { vsprintf( buf, msg, ap ); va_end( ap ); (*handler)( QtWarningMsg, buf ); } else { vfprintf( stderr, msg, ap ); va_end( ap ); fprintf( stderr, "\n" ); // add newline }}void qFatal( const char *msg, ... ){ char buf[8196]; va_list ap; va_start( ap, msg ); // use variable arg list if ( handler ) { vsprintf( buf, msg, ap ); va_end( ap ); (*handler)( QtFatalMsg, buf ); } else { vfprintf( stderr, msg, ap ); va_end( ap ); fprintf( stderr, "\n" ); // add newline#if defined(_OS_UNIX_) && defined(DEBUG) abort(); // trap; generates core dump#else exit( 1 ); // goodbye cruel world#endif }}// yet again, copiedvoid fatal( const char *msg, ... ){ char buf[8196]; va_list ap; va_start( ap, msg ); // use variable arg list if ( handler ) { vsprintf( buf, msg, ap ); va_end( ap ); (*handler)( QtFatalMsg, buf ); } else { vfprintf( stderr, msg, ap ); va_end( ap ); fprintf( stderr, "\n" ); // add newline#if defined(_OS_UNIX_) && defined(DEBUG) abort(); // trap; generates core dump#else exit( 1 ); // goodbye cruel world#endif }}#endif/*! \fn void ASSERT( bool test ) \relates QApplication Prints a warning message containing the source code file name and line number if \e test is FALSE. This is really a macro defined in qglobal.h. ASSERT is useful for testing required conditions in your program. Example: \code // // File: div.cpp // #include <qglobal.h> int divide( int a, int b ) { ASSERT( b != 0 ); // this is line 9 return a/b; } \endcode If \c b is zero, the 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 CHECK_PTR( void *p ) \relates QApplication If \e p is null, a fatal messages says that the program ran out of memory and exits. If \e p is not null, nothing happens. This is really a macro defined in qglobal.h. Example: \code int *a; CHECK_PTR( a = new int[80] ); // never do this! // do this instead: a = new int[80]; CHECK_PTR( a ); // this is fine \endcode \sa qFatal(), \link debug.html Debugging\endlink*///// The CHECK_PTR macro calls this function to check if an allocation went ok.//bool qt_check_pointer( bool c, const char *n, int l ){ if ( c ) qFatal( "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(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. 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(); // dump core on purpose } } 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*/msg_handler qInstallMsgHandler( msg_handler h ){ msg_handler old = handler; handler = h; return old;}#ifdef _WS_WIN_bool qt_winunicode=FALSE;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -