9#include <QtCore/qobject.h>
10#include <QtCore/qdeadlinetimer.h>
16#if defined(Q_CC_MSVC) && defined(Q_PROCESSOR_X86)
25class QAbstractEventDispatcher;
28class Q_CORE_EXPORT
QThread :
public QObject
32 Q_DECL_PURE_FUNCTION
static Qt::HANDLE currentThreadId()
noexcept;
33 static QThread *currentThread();
34 static bool isMainThread()
noexcept;
35 static int idealThreadCount()
noexcept;
36 static void yieldCurrentThread();
38 explicit QThread(QObject *parent =
nullptr);
55 enum class QualityOfService {
60 Q_ENUM(QualityOfService)
62 void setPriority(Priority priority);
63 Priority priority()
const;
65 bool isFinished()
const;
66 bool isRunning()
const;
68 void requestInterruption();
69 bool isInterruptionRequested()
const;
71 void setStackSize(uint stackSize);
72 uint stackSize()
const;
74 QAbstractEventDispatcher *eventDispatcher()
const;
75 void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
77 bool event(QEvent *event) override;
78 int loopLevel()
const;
80 bool isCurrentThread()
const noexcept;
82 void setServiceLevel(QualityOfService serviceLevel);
83 QualityOfService serviceLevel()
const;
85 template <
typename Function,
typename... Args>
86 [[nodiscard]]
static QThread *create(Function &&f, Args &&... args);
89 void start(Priority = InheritPriority);
91 void exit(
int retcode = 0);
95 bool wait(QDeadlineTimer deadline = QDeadlineTimer(QDeadlineTimer::Forever));
96 bool wait(
unsigned long time)
98 if (time == (std::numeric_limits<
unsigned long>::max)())
99 return wait(QDeadlineTimer(QDeadlineTimer::Forever));
100 return wait(QDeadlineTimer(time));
103 static void sleep(
unsigned long);
104 static void msleep(
unsigned long);
105 static void usleep(
unsigned long);
106 static void sleep(std::chrono::nanoseconds nsec);
109 void started(QPrivateSignal);
110 void finished(QPrivateSignal);
116 static void setTerminationEnabled(
bool enabled =
true);
119 QThread(QThreadPrivate &dd, QObject *parent =
nullptr);
122 Q_DECLARE_PRIVATE(QThread)
123 friend class QEventLoopLocker;
125 [[nodiscard]]
static QThread *createThreadImpl(std::future<
void> &&future);
126 Q_DECL_PURE_FUNCTION
static Qt::HANDLE currentThreadIdImpl()
noexcept;
128 friend class QCoreApplication;
129 friend class QThreadData;
132template <
typename Function,
typename... Args>
133QThread *QThread::create(Function &&f, Args &&... args)
135 using DecayedFunction =
typename std::decay<Function>::type;
136 auto threadFunction =
137 [f =
static_cast<DecayedFunction>(std::forward<Function>(f))](
auto &&... largs)
mutable ->
void
139 (
void)std::invoke(std::move(f), std::forward<
decltype(largs)>(largs)...);
142 return createThreadImpl(std::async(std::launch::deferred,
143 std::move(threadFunction),
144 std::forward<Args>(args)...));
148
149
150
151
152
153
154
155
156
157
158
159
160inline Qt::HANDLE QThread::currentThreadId()
noexcept
163#define QT_HAS_FAST_CURRENT_THREAD_ID
165 static_assert(
sizeof(tid) ==
sizeof(
void*));
167#if defined(Q_PROCESSOR_X86_32) && ((defined(Q_OS_LINUX) && defined(__GLIBC__
)) || defined(Q_OS_FREEBSD))
168 __asm__(
"mov %%gs:%c1, %0" :
"=r" (tid) :
"i" (2 *
sizeof(
void*)) : );
169#elif defined(Q_PROCESSOR_X86_64) && defined(Q_OS_DARWIN)
171 __asm__(
"mov %%gs:0, %0" :
"=r" (tid) : : );
172#elif defined(Q_PROCESSOR_X86_64) && ((defined(Q_OS_LINUX) && defined(__GLIBC__
)) || defined(Q_OS_FREEBSD))
174 __asm__(
"mov %%fs:%c1, %0" :
"=r" (tid) :
"i" (2 *
sizeof(
void*)) : );
175#elif defined(Q_PROCESSOR_X86_64) && defined(Q_OS_WIN)
179# if defined(Q_CC_MINGW)
180 __asm__(
"movq %%gs:0x30, %0" :
"=r" (tib) : :);
182 tib =
reinterpret_cast<quint8 *>(__readgsqword(0x30));
185 tid = *
reinterpret_cast<Qt::HANDLE *>(tib + 0x48);
186#elif defined(Q_PROCESSOR_X86_32) && defined(Q_OS_WIN)
189# if defined(Q_CC_MINGW)
190 __asm__(
"movl %%fs:0x18, %0" :
"=r" (tib) : :);
192 tib =
reinterpret_cast<quint8 *>(__readfsdword(0x18));
195 tid = *
reinterpret_cast<Qt::HANDLE *>(tib + 0x24);
197#undef QT_HAS_FAST_CURRENT_THREAD_ID
198 tid = currentThreadIdImpl();
QByteArray & operator*() noexcept
QByteArray::Base64DecodingStatus decodingStatus
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
void swap(QByteArray::FromBase64Result &other) noexcept
operator bool() const noexcept
\variable QByteArray::FromBase64Result::decoded
const QByteArray & operator*() const noexcept
Returns the decoded byte array.
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
\inmodule QtCore\reentrant
int initFrom(const QMessageLogContext &logContext)
void populateBacktrace(int frameCount)
QInternalMessageLogContext(const QMessageLogContext &logContext, const QLoggingCategory &categoryOverride)
std::optional< BacktraceStorage > backtrace
static constexpr int DefaultBacktraceDepth
constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
constexpr QMessageLogContext() noexcept=default
QDebug debug(CategoryFunction catFunc) const
QDebug debug(const QLoggingCategory &cat) const
Logs a debug message into category cat using a QDebug stream.
void void void void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QDebug debug() const
Logs a debug message using a QDebug stream.
QDebug info(const QLoggingCategory &cat) const
Logs an informational message into the category cat using a QDebug stream.
QDebug info() const
Logs an informational message using a QDebug stream.
QNoDebug noDebug(...) const noexcept
QDebug info(CategoryFunction catFunc) const
static Q_CONSTINIT thread_local bool msgHandlerGrabbed
static const char ifCriticalTokenC[]
static bool grabMessageHandler()
void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, const QString &message)
static const char emptyTokenC[]
static Q_NEVER_INLINE void qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, va_list ap)
static void preformattedMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &formattedMessage)
static bool systemHasStderr()
Returns true if writing to stderr is supported.
static const char endifTokenC[]
static bool isDefaultCategory(const char *category)
static const char messageTokenC[]
static bool qt_append_thread_name_to(QString &message)
static constexpr SystemMessageSink systemMessageSink
static void qt_maybe_message_fatal(QtMsgType, const QMessageLogContext &context, String &&message)
\inmodule QtCore \title Qt Logging Types
#define HANDLE_IF_TOKEN(LEVEL)
Q_DECLARE_TYPEINFO(QMessagePattern::BacktraceParams, Q_RELOCATABLE_TYPE)
static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &buf)
static const char timeTokenC[]
static bool isFatalCountDown(const char *varname, QBasicAtomicInt &n)
void qErrnoWarning(int code, const char *msg,...)
static const char qthreadptrTokenC[]
static const char fileTokenC[]
static const char ifDebugTokenC[]
static const char ifFatalTokenC[]
static const char categoryTokenC[]
static void stderr_message_handler(QtMsgType type, const QMessageLogContext &context, const QString &formattedMessage)
static const char lineTokenC[]
static const char typeTokenC[]
static void ungrabMessageHandler()
static void copyInternalContext(QInternalMessageLogContext *self, const QMessageLogContext &logContext) noexcept
static const char ifCategoryTokenC[]
static int checked_var_value(const char *varname)
static const char threadnameTokenC[]
static const char pidTokenC[]
Q_TRACE_POINT(qtcore, qt_message_print, int type, const char *category, const char *function, const char *file, int line, const QString &message)
static const char threadidTokenC[]
static QString formatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &str)
static const char backtraceTokenC[]
void qErrnoWarning(const char *msg,...)
static const char functionTokenC[]
static const char ifWarningTokenC[]
static const char appnameTokenC[]
static bool isFatal(QtMsgType msgType)
static const char ifInfoTokenC[]
QtMessageHandler qInstallMessageHandler(QtMessageHandler h)
static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message)
static bool stderrHasConsoleAttached()
Returns true if writing to stderr will end up in a console/terminal visible to the user.
void qSetMessagePattern(const QString &pattern)
QDebug printAssociativeContainer(QDebug debug, const char *which, const AssociativeContainer &c)
bool shouldLogToStderr()
Returns true if logging stderr should be ensured.
QDebug printSequentialContainer(QDebug debug, const char *which, const SequentialContainer &c)
QByteArray operator""_ba(const char *str, size_t size) noexcept
QT_BEGIN_NAMESPACE Q_NORETURN void qAbort()
QByteArray operator+(const QByteArray &a1, const char *a2)
QByteArray qUncompress(const QByteArray &data)
QByteArray operator+(char a1, const QByteArray &a2)
QByteArray operator+(QByteArray &&lhs, char rhs)
QByteArray operator+(const QByteArray &a1, char a2)
QByteArray operator+(const char *a1, const QByteArray &a2)
QByteArray operator+(QByteArray &&lhs, const QByteArray &rhs)
qsizetype erase_if(QByteArray &ba, Predicate pred)
QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
QByteArray qCompress(const QByteArray &data, int compressionLevel=-1)
qsizetype erase(QByteArray &ba, const T &t)
QByteArray operator+(QByteArray &&lhs, const char *rhs)
#define __has_cpp_attribute(x)
void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, Int value)
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, quint64 value)
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, uint value)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
#define QT_MESSAGELOG_FUNC
#define QT_MESSAGELOG_FILE
#define QT_MESSAGE_LOGGER_NORETURN
#define QT_MESSAGELOG_LINE
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern)
#define QT_MESSAGELOGCONTEXT
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const QString &message)
void(* QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &)
QString backtraceSeparator
void setPattern(const QString &pattern)
std::unique_ptr< std::unique_ptr< const char[]>[]> literals
std::chrono::steady_clock::time_point appStartTime
std::unique_ptr< const char *[]> tokens
QList< QString > timeArgs
static constexpr bool Value
static constexpr bool Value