Qt 4.8
Functions
qsystemerror.cpp File Reference
#include <qglobal.h>
#include "qsystemerror_p.h"
#include <windows.h>

Go to the source code of this file.

Functions

static QString standardLibraryErrorString (int errorCode)
 
static QString windowsErrorString (int errorCode)
 

Function Documentation

◆ standardLibraryErrorString()

static QString standardLibraryErrorString ( int  errorCode)
static

Definition at line 104 of file qsystemerror.cpp.

Referenced by QSystemError::toString().

105 {
106  const char *s = 0;
107  QString ret;
108  switch (errorCode) {
109  case 0:
110  break;
111  case EACCES:
112  s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");
113  break;
114  case EMFILE:
115  s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");
116  break;
117  case ENOENT:
118  s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");
119  break;
120  case ENOSPC:
121  s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");
122  break;
123  default: {
124  #ifdef Q_OS_WINCE
125  ret = windowsErrorString(errorCode);
126  #else
127  #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX)
128  QByteArray buf(1024, '\0');
129  ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf);
130  #else
131  ret = QString::fromLocal8Bit(strerror(errorCode));
132  #endif
133  #endif
134  break; }
135  }
136  if (s) {
137  // ######## this breaks moc build currently
138  // ret = QCoreApplication::translate("QIODevice", s);
139  ret = QString::fromLatin1(s);
140  }
141  return ret.trimmed();
142 }
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
static QString windowsErrorString(int errorCode)
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
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

◆ windowsErrorString()

static QString windowsErrorString ( int  errorCode)
static

Definition at line 84 of file qsystemerror.cpp.

Referenced by standardLibraryErrorString(), and QSystemError::toString().

85 {
86  QString ret;
87  wchar_t *string = 0;
88  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
89  NULL,
90  errorCode,
91  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
92  (LPWSTR)&string,
93  0,
94  NULL);
95  ret = QString::fromWCharArray(string);
96  LocalFree((HLOCAL)string);
97 
98  if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)
99  ret = QString::fromLatin1("The specified module could not be found.");
100  return ret;
101 }
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
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