Qt 4.8
Classes | Typedefs | Functions | Variables
qglobal.cpp File Reference
#include "qplatformdefs.h"
#include "qstring.h"
#include "qvector.h"
#include "qlist.h"
#include "qthreadstorage.h"
#include "qdir.h"
#include "qstringlist.h"
#include "qdatetime.h"
#include <private/qthread_p.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stdarg.h>
#include <string.h>
#include <string>
#include <exception>
#include "private/qcore_mac_p.h"
#include "qnamespace.h"

Go to the source code of this file.

Classes

struct  QInternal_CallBackTable
 

Typedefs

typedef QThreadStorage< SeedStorageType * > SeedStorage
 
typedef uint SeedStorageType
 

Functions

static QSysInfo::MacVersion macVersion ()
 Use QSysInfo::MacintoshVersion instead. More...
 
void qBadAlloc ()
 
static void qEmergencyOut (QtMsgType msgType, const char *msg, va_list ap)
 Uses a local buffer to output the message. More...
 
void qErrnoWarning (const char *msg,...)
 
void qErrnoWarning (int code, const char *msg,...)
 
QtMsgHandler qInstallMsgHandler (QtMsgHandler h)
 
void * qMemCopy (void *dest, const void *src, size_t n)
 
void * qMemSet (void *dest, int c, size_t n)
 
bool qSharedBuild ()
 
void qt_assert (const char *assertion, const char *file, int line)
 
void qt_assert_x (const char *where, const char *what, const char *file, int line)
 
void qt_check_pointer (const char *n, int l)
 
QString qt_error_string (int errorCode)
 
Q_CORE_EXPORT unsigned int qt_int_sqrt (unsigned int n)
 
static void qt_message (QtMsgType msgType, const char *msg, va_list ap)
 
void qt_message_output (QtMsgType msgType, const char *buf)
 
void qt_set_current_thread_to_main_thread ()
 

Variables

static QtMsgHandler handler = 0
 

Typedef Documentation

◆ SeedStorage

Definition at line 3096 of file qglobal.cpp.

◆ SeedStorageType

Definition at line 3093 of file qglobal.cpp.

Function Documentation

◆ macVersion()

Qt::MacintoshVersion QApplication::macVersion ( )
static

Use QSysInfo::MacintoshVersion instead.

Definition at line 2077 of file qglobal.cpp.

Referenced by QApplication::isLeftToRight().

2078 {
2079 #if !defined(Q_OS_IOS)
2080  SInt32 gestalt_version;
2081  if (Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) {
2082  return QSysInfo::MacVersion(((gestalt_version & 0x00F0) >> 4) + 2);
2083  }
2084 #endif
2085  return QSysInfo::MV_Unknown;
2086 }
MacVersion
This enum provides symbolic names for the various versions of the OS X operating system.
Definition: qglobal.h:1618

◆ qBadAlloc()

void qBadAlloc ( )

Definition at line 2451 of file qglobal.cpp.

2452 {
2453  QT_THROW(std::bad_alloc());
2454 }
#define QT_THROW(A)
Definition: qglobal.h:1538

◆ qEmergencyOut()

static void qEmergencyOut ( QtMsgType  msgType,
const char *  msg,
va_list  ap 
)
static

Uses a local buffer to output the message.

Warning
This function is not part of the public interface. Not locale safe + cuts off everything after character 255, but will work in out of memory situations.

Definition at line 2785 of file qglobal.cpp.

Referenced by qt_message().

2786 {
2787  char emergency_buf[256] = { '\0' };
2788  emergency_buf[255] = '\0';
2789  if (msg)
2790  qvsnprintf(emergency_buf, 255, msg, ap);
2791  qt_message_output(msgType, emergency_buf);
2792 }
int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
A portable vsnprintf() function.
Definition: qvsnprintf.cpp:78
void qt_message_output(QtMsgType msgType, const char *buf)
Definition: qglobal.cpp:2712

◆ qErrnoWarning() [1/2]

void qErrnoWarning ( const char *  msg,
  ... 
)

Definition at line 2954 of file qglobal.cpp.

Referenced by QFontEngineDirectWrite::addGlyphsToPath(), QWin32PrintEngine::begin(), QFontEngineDirectWrite::boundingBox(), QWindowsXPStylePrivate::buffer(), QFontEngineDirectWrite::canRender(), QGLContext::choosePixelFormat(), QWin32PrintEnginePrivate::composeGdiPath(), QWin32PrintEngine::drawPixmap(), QWin32PrintEngine::drawTiledPixmap(), QThreadPrivate::finish(), QPixmap::fromWinHBITMAP(), QFontEngineDirectWrite::getSfntTableData(), QFontEngineDirectWrite::imageForGlyph(), initFontInfo(), QAxBase::initialize(), QWin32PrintEnginePrivate::initialize(), QAxBase::initializeLicensedHelper(), QAxBase::initializeRemote(), loadEngine(), QOpenKODEWindow::lower(), QWin32PrintEngine::newPage(), QFontEngineQPF::QFontEngineQPF(), QFontEngineWin::QFontEngineWin(), QOpenKODEIntegration::QOpenKODEIntegration(), QOpenKODEScreen::QOpenKODEScreen(), QOpenKODEWindow::QOpenKODEWindow(), QQnxMouseHandler::QQnxMouseHandler(), qt_reg_winclass(), qt_tablet_cleanup_wce(), QWin32PrintEnginePrivate::queryResolutions(), QWaylandDisplay::QWaylandDisplay(), QWSQnxKeyboardHandler::QWSQnxKeyboardHandler(), QOpenKODEWindow::raise(), QFontEngineDirectWrite::recalcAdvances(), QWindowsMime::registerMimeType(), QEventDispatcherWin32Private::registerTimer(), QWidget::releaseDC(), QFontEngineQPF::remapFontData(), resolveGdi32(), QWindowsFileSystemWatcherEngineThread::run(), QOpenKODEWindow::setGeometry(), QOpenKODEWindow::setVisible(), QWSQnxKeyboardHandler::socketActivated(), QQnxMouseHandler::socketActivated(), QFontEngineDirectWrite::stringToCMap(), QPixmap::toWinHBITMAP(), QClipboard::~QClipboard(), QFontEngineQPF::~QFontEngineQPF(), and QFontEngineWin::~QFontEngineWin().

2955 {
2956  // qt_error_string() will allocate anyway, so we don't have
2957  // to be careful here (like we do in plain qWarning())
2958  QString buf;
2959  va_list ap;
2960  va_start(ap, msg);
2961  if (msg)
2962  buf.vsprintf(msg, ap);
2963  va_end(ap);
2964 
2965  qCritical("%s (%s)", buf.toLocal8Bit().constData(), qt_error_string(-1).toLocal8Bit().constData());
2966 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & vsprintf(const char *format, va_list ap)
Equivalent method to sprintf(), but takes a va_list ap instead a list of variable arguments...
Definition: qstring.cpp:5587
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
Q_CORE_EXPORT void qCritical(const char *,...)

◆ qErrnoWarning() [2/2]

void qErrnoWarning ( int  code,
const char *  msg,
  ... 
)

Definition at line 2968 of file qglobal.cpp.

2969 {
2970  // qt_error_string() will allocate anyway, so we don't have
2971  // to be careful here (like we do in plain qWarning())
2972  QString buf;
2973  va_list ap;
2974  va_start(ap, msg);
2975  if (msg)
2976  buf.vsprintf(msg, ap);
2977  va_end(ap);
2978 
2979  qCritical("%s (%s)", buf.toLocal8Bit().constData(), qt_error_string(code).toLocal8Bit().constData());
2980 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & vsprintf(const char *format, va_list ap)
Equivalent method to sprintf(), but takes a va_list ap instead a list of variable arguments...
Definition: qstring.cpp:5587
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
Q_CORE_EXPORT void qCritical(const char *,...)

◆ qInstallMsgHandler()

QtMsgHandler qInstallMsgHandler ( QtMsgHandler  h)

Definition at line 2698 of file qglobal.cpp.

Referenced by QClassFactory::CreateInstanceHelper(), QTest::messageHandler(), QErrorMessage::qtHandler(), qWinMain(), QTestLog::startLogging(), QTestLog::stopLogging(), and QErrorMessage::~QErrorMessage().

2699 {
2700  QtMsgHandler old = handler;
2701  handler = h;
2702 #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
2703  if (!handler && usingWinMain)
2705 #endif
2706  return old;
2707 }
void(* QtMsgHandler)(QtMsgType, const char *)
Definition: qglobal.h:1885
static QtMsgHandler handler
Definition: qglobal.cpp:2511
bool usingWinMain
void qWinMsgHandler(QtMsgType t, const char *str)

◆ qMemCopy()

void* qMemCopy ( void *  dest,
const void *  src,
size_t  n 
)

◆ qMemSet()

void* qMemSet ( void *  dest,
int  c,
size_t  n 
)

◆ qSharedBuild()

bool qSharedBuild ( )

Definition at line 1228 of file qglobal.cpp.

1229 {
1230 #ifdef QT_SHARED
1231  return true;
1232 #else
1233  return false;
1234 #endif
1235 }

◆ qt_assert()

void qt_assert ( const char *  assertion,
const char *  file,
int  line 
)

Definition at line 2459 of file qglobal.cpp.

2460 {
2461  qFatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
2462 }
Q_CORE_EXPORT void qFatal(const char *,...)

◆ qt_assert_x()

void qt_assert_x ( const char *  where,
const char *  what,
const char *  file,
int  line 
)

Definition at line 2467 of file qglobal.cpp.

2468 {
2469  qFatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
2470 }
Q_CORE_EXPORT void qFatal(const char *,...)

◆ qt_check_pointer()

void qt_check_pointer ( const char *  n,
int  l 
)

Definition at line 2442 of file qglobal.cpp.

2443 {
2444  qFatal("In file %s, line %d: Out of memory", n, l);
2445 }
Q_CORE_EXPORT void qFatal(const char *,...)
QFactoryLoader * l

◆ qt_error_string()

QString qt_error_string ( int  errorCode)

Definition at line 2600 of file qglobal.cpp.

Referenced by QLocalServerPrivate::addListener(), QFSFileEnginePrivate::closeFdFh(), QProcessPrivate::execChild(), QFSFileEnginePrivate::flushFh(), QFSFileEnginePrivate::longFileName(), QFSFileEnginePrivate::map(), QFSFileEnginePrivate::nativeOpen(), QFSFileEnginePrivate::nativeRead(), QFSFileEnginePrivate::openFd(), QFSFileEnginePrivate::openFh(), QProcessPrivate::processStarted(), qErrnoWarning(), qt_create_commandline(), qt_create_pipe(), qt_message(), qt_parse_pattern(), QNativeSocketEngine::read(), QFSFileEnginePrivate::readFdFh(), QFSFileEnginePrivate::readLineFdFh(), report_error(), QFSFileEnginePrivate::seekFdFh(), QFilePrivate::setError(), QFSFileEngine::setSize(), QThread::start(), QProcessPrivate::startProcess(), QThread::terminate(), QFSFileEnginePrivate::unmap(), QFSFileEnginePrivate::writeFdFh(), and QProcessPrivate::writeToStdin().

2601 {
2602  const char *s = 0;
2603  QString ret;
2604  if (errorCode == -1) {
2605 #if defined(Q_OS_WIN)
2606  errorCode = GetLastError();
2607 #else
2608  errorCode = errno;
2609 #endif
2610  }
2611  switch (errorCode) {
2612  case 0:
2613  break;
2614  case EACCES:
2615  s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");
2616  break;
2617  case EMFILE:
2618  s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");
2619  break;
2620  case ENOENT:
2621  s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");
2622  break;
2623  case ENOSPC:
2624  s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");
2625  break;
2626  default: {
2627 #ifdef Q_OS_WIN
2628  wchar_t *string = 0;
2629  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
2630  NULL,
2631  errorCode,
2632  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
2633  (LPWSTR)&string,
2634  0,
2635  NULL);
2636  ret = QString::fromWCharArray(string);
2637  LocalFree((HLOCAL)string);
2638 
2639  if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)
2640  ret = QString::fromLatin1("The specified module could not be found.");
2641 #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX)
2642  QByteArray buf(1024, '\0');
2643  ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf);
2644 #else
2645  ret = QString::fromLocal8Bit(strerror(errorCode));
2646 #endif
2647  break; }
2648  }
2649  if (s)
2650  // ######## this breaks moc build currently
2651 // ret = QCoreApplication::translate("QIODevice", s);
2652  ret = QString::fromLatin1(s);
2653  return ret.trimmed();
2654 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int errno

◆ qt_int_sqrt()

Q_CORE_EXPORT unsigned int qt_int_sqrt ( unsigned int  n)

Definition at line 2478 of file qglobal.cpp.

Referenced by QTextDocument::adjustSize(), and qt_int_sqrt().

2479 {
2480  // n must be in the range 0...UINT_MAX/2-1
2481  if (n >= (UINT_MAX>>2)) {
2482  unsigned int r = 2 * qt_int_sqrt(n / 4);
2483  unsigned int r2 = r + 1;
2484  return (n >= r2 * r2) ? r2 : r;
2485  }
2486  uint h, p= 0, q= 1, r= n;
2487  while (q <= n)
2488  q <<= 2;
2489  while (q != 1) {
2490  q >>= 2;
2491  h= p + q;
2492  p >>= 1;
2493  if (r >= h) {
2494  p += q;
2495  r -= h;
2496  }
2497  }
2498  return p;
2499 }
unsigned int uint
Definition: qglobal.h:996
Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
Definition: qglobal.cpp:2478

◆ qt_message()

static void qt_message ( QtMsgType  msgType,
const char *  msg,
va_list  ap 
)
static
Warning
This function is not part of the public interface.

Definition at line 2798 of file qglobal.cpp.

Referenced by qErrnoWarning().

2799 {
2800 #if !defined(QT_NO_EXCEPTIONS)
2801  if (std::uncaught_exception()) {
2802  qEmergencyOut(msgType, msg, ap);
2803  return;
2804  }
2805 #endif
2806  QByteArray buf;
2807  if (msg) {
2808  QT_TRY {
2809  buf = QString().vsprintf(msg, ap).toLocal8Bit();
2810  } QT_CATCH(const std::bad_alloc &) {
2811 #if !defined(QT_NO_EXCEPTIONS)
2812  qEmergencyOut(msgType, msg, ap);
2813  // don't rethrow - we use qWarning and friends in destructors.
2814  return;
2815 #endif
2816  }
2817  }
2818  qt_message_output(msgType, buf.constData());
2819 }
static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap)
Uses a local buffer to output the message.
Definition: qglobal.cpp:2785
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & vsprintf(const char *format, va_list ap)
Equivalent method to sprintf(), but takes a va_list ap instead a list of variable arguments...
Definition: qstring.cpp:5587
#define QT_CATCH(A)
Definition: qglobal.h:1537
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void qt_message_output(QtMsgType msgType, const char *buf)
Definition: qglobal.cpp:2712
#define QT_TRY
Definition: qglobal.h:1536

◆ qt_message_output()

void qt_message_output ( QtMsgType  msgType,
const char *  buf 
)
Warning
This function is not part of the public interface.

Definition at line 2712 of file qglobal.cpp.

Referenced by qEmergencyOut(), qt_message(), and QDebug::~QDebug().

2713 {
2714  if (handler) {
2715  (*handler)(msgType, buf);
2716  } else {
2717 #if defined(Q_CC_MWERKS) && defined(Q_OS_MACX)
2718  mac_default_handler(buf);
2719 #elif defined(QT_USE_SLOG2)
2720  slog2_default_handler(msgType, buf);
2721 #elif defined(Q_OS_WINCE)
2722  QString fstr = QString::fromLatin1(buf);
2723  fstr += QLatin1Char('\n');
2724  OutputDebugString(reinterpret_cast<const wchar_t *> (fstr.utf16()));
2725 #elif defined(Q_OS_SYMBIAN)
2726  // RDebug::Print has a cap of 256 characters so break it up
2727  char format[] = "[Qt Message] %S";
2728  const int maxBlockSize = 256 - sizeof(format);
2729  const TPtrC8 ptr(reinterpret_cast<const TUint8*>(buf));
2730  for (int i = 0; i < ptr.Length(); i += maxBlockSize) {
2731  TPtrC8 part(ptr.Mid(i, qMin(maxBlockSize, ptr.Length()-i)));
2732  RDebug::Printf(format, &part);
2733  }
2734 #else
2735  fprintf(stderr, "%s\n", buf);
2736  fflush(stderr);
2737 #endif
2738  }
2739 
2740  if (msgType == QtFatalMsg
2741  || (msgType == QtWarningMsg
2742  && (!qgetenv("QT_FATAL_WARNINGS").isNull())) ) {
2743 
2744 #if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR)
2745  // get the current report mode
2746  int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW);
2747  _CrtSetReportMode(_CRT_ERROR, reportMode);
2748 #if !defined(Q_OS_WINCE)
2749  int ret = _CrtDbgReport(_CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, buf);
2750 #else
2751  int ret = _CrtDbgReportW(_CRT_ERROR, _CRT_WIDE(__FILE__),
2752  __LINE__, _CRT_WIDE(QT_VERSION_STR), reinterpret_cast<const wchar_t *> (QString::fromLatin1(buf).utf16()));
2753 #endif
2754  if (ret == 0 && reportMode & _CRTDBG_MODE_WNDW)
2755  return; // ignore
2756  else if (ret == 1)
2757  _CrtDbgBreak();
2758 #endif
2759 
2760 #if defined(Q_OS_SYMBIAN)
2761  __DEBUGGER(); // on the emulator, get the debugger to kick in if there's one around
2762  TBuf<256> tmp;
2763  TPtrC8 ptr(reinterpret_cast<const TUint8*>(buf));
2764  TInt len = Min(tmp.MaxLength(), ptr.Length());
2765  tmp.Copy(ptr.Left(len));
2766  // Panic the current thread. We don't use real panic codes, so 0 has no special meaning.
2767  User::Panic(tmp, 0);
2768 #elif (defined(Q_OS_UNIX) || defined(Q_CC_MINGW))
2769  abort(); // trap; generates core dump
2770 #else
2771  exit(1); // goodbye cruel world
2772 #endif
2773  }
2774 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QtMsgHandler handler
Definition: qglobal.cpp:2511
#define QT_VERSION_STR
This macro expands to a string that specifies Qt&#39;s version number (for example, "4.
Definition: qglobal.h:47
const T * ptr(const T &t)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ qt_set_current_thread_to_main_thread()

void qt_set_current_thread_to_main_thread ( )

Definition at line 355 of file qcoreapplication.cpp.

Referenced by QInternal::activateCallbacks(), and QInternal::callFunction().

356 {
358 }
static QThread * theMainThread
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419

Variable Documentation

◆ handler

QtMsgHandler handler = 0
static

Definition at line 2511 of file qglobal.cpp.

Referenced by qInstallMsgHandler(), and qt_message_output().