Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qqmlthread_p.h
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant
4
5
#
ifndef
QQMLTHREAD_P_H
6
#
define
QQMLTHREAD_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
20
#
include
<
QtCore
/
qglobal
.
h
>
21
22
#
include
<
private
/
qintrusivelist_p
.
h
>
23
24
QT_BEGIN_NAMESPACE
25
26
class
QThread;
27
class
QMutex;
28
29
class
QQmlThreadPrivate
;
30
class
QQmlThread
31
{
32
public
:
33
QQmlThread
();
34
virtual
~
QQmlThread
();
35
36
void
lock
();
37
void
unlock
();
38
void
wakeOne
();
39
void
wait
();
40
41
bool
isThisThread
()
const
;
42
bool
isParentThread
()
const
;
43
44
// Synchronously invoke a method in the thread
45
template
<
typename
Method,
typename
...Args>
46
void
callMethodInThread
(Method &&method, Args &&...args);
47
48
// Synchronously invoke a method in the main thread. If the main thread is
49
// blocked in a callMethodInThread() call, the call is made from within that
50
// call.
51
template
<
typename
Method,
typename
...Args>
52
void
callMethodInMain
(Method &&method, Args &&...args);
53
54
// Asynchronously invoke a method in the thread.
55
template
<
typename
Method,
typename
...Args>
56
void
postMethodToThread
(Method &&method, Args &&...args);
57
58
// Asynchronously invoke a method in the main thread.
59
template
<
typename
Method,
typename
...Args>
60
void
postMethodToMain
(Method &&method, Args &&...args);
61
62
void
waitForNextMessage
();
63
void
discardMessages
();
64
65
void
startup
();
66
void
restart
();
67
void
shutdown
();
68
bool
isRunning
()
const
;
69
70
protected
:
71
QThread *
thread
()
const
;
72
QObject
*
threadObject
()
const
;
73
74
private
:
75
friend
class
QQmlThreadPrivate
;
76
77
struct
Message {
78
Message() : next(
nullptr
) {}
79
virtual
~Message() {}
80
Message *next;
81
virtual
void
call(
QQmlThread
*) = 0;
82
};
83
template
<
typename
Method,
typename
...Args>
84
Message *createMessageFromMethod(Method &&method, Args &&...args);
85
void
internalCallMethodInThread(Message *);
86
void
internalCallMethodInMain(Message *);
87
void
internalPostMethodToThread(Message *);
88
void
internalPostMethodToMain(Message *);
89
QQmlThreadPrivate
*d;
90
};
91
92
namespace
QtPrivate
{
93
template
<
typename
>
struct
member_function_traits
;
94
95
template
<
typename
Return,
typename
Object,
typename
... Args>
96
struct
member_function_traits
<Return (
Object
::*)(Args...)>
97
{
98
using
class_type
= Object;
99
};
100
}
101
102
template
<
typename
Method,
typename
...Args>
103
QQmlThread
::Message *
QQmlThread
::createMessageFromMethod(Method &&method, Args &&...args)
104
{
105
struct
I :
public
Message {
106
Method m;
107
std::tuple<std::decay_t<Args>...> arguments;
108
I(Method &&method, Args&& ...args) : m(std::forward<Method>(method)), arguments(std::forward<Args>(args)...) {}
109
void
call(
QQmlThread
*thread)
override
{
110
using
class_type =
typename
QtPrivate
::
member_function_traits
<Method>::class_type;
111
class_type *me =
static_cast
<class_type *>(thread);
112
std::apply(m, std::tuple_cat(std::make_tuple(me), arguments));
113
}
114
};
115
return
new
I(std::forward<Method>(method), std::forward<Args>(args)...);
116
}
117
118
template
<
typename
Method,
typename
...Args>
119
void
QQmlThread
::
callMethodInMain
(Method &&method, Args&& ...args)
120
{
121
Message *m = createMessageFromMethod(std::forward<Method>(method), std::forward<Args>(args)...);
122
internalCallMethodInMain(m);
123
}
124
125
template
<
typename
Method,
typename
...Args>
126
void
QQmlThread
::
callMethodInThread
(Method &&method, Args&& ...args)
127
{
128
Message *m = createMessageFromMethod(std::forward<Method>(method), std::forward<Args>(args)...);
129
internalCallMethodInThread(m);
130
}
131
132
template
<
typename
Method,
typename
...Args>
133
void
QQmlThread
::
postMethodToThread
(Method &&method, Args&& ...args)
134
{
135
Message *m = createMessageFromMethod(std::forward<Method>(method), std::forward<Args>(args)...);
136
internalPostMethodToThread(m);
137
}
138
139
template
<
typename
Method,
typename
...Args>
140
void
QQmlThread
::
postMethodToMain
(Method &&method, Args&& ...args)
141
{
142
Message *m = createMessageFromMethod(std::forward<Method>(method), std::forward<Args>(args)...);
143
internalPostMethodToMain(m);
144
}
145
146
QT_END_NAMESPACE
147
148
#
endif
// QQMLTHREAD_P_H
QQmlThreadPrivate::QQmlThreadPrivate
QQmlThreadPrivate(QQmlThread *q)
Definition
qqmlthread_stub.cpp:25
QQmlThreadPrivate::MessageList
QFieldList< QQmlThread::Message, &QQmlThread::Message::next > MessageList
Definition
qqmlthread_stub.cpp:23
QQmlThreadPrivate::event
bool event(QEvent *e) override
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition
qqmlthread_stub.cpp:27
QQmlThread
\inmodule QtQml
Definition
qqmlthread_p.h:31
QQmlThread::lock
void lock()
Definition
qqmlthread_impl.cpp:232
QQmlThread::QQmlThread
QQmlThread()
Definition
qqmlthread_impl.cpp:167
QQmlThread::postMethodToThread
void postMethodToThread(Method &&method, Args &&...args)
Definition
qqmlthread_p.h:133
QQmlThread::thread
QThread * thread() const
Definition
qqmlthread_impl.cpp:263
QQmlThread::discardMessages
void discardMessages()
Definition
qqmlthread_impl.cpp:408
QQmlThread::unlock
void unlock()
Definition
qqmlthread_impl.cpp:237
QQmlThread::isRunning
bool isRunning() const
Definition
qqmlthread_impl.cpp:227
QQmlThread::wait
void wait()
Definition
qqmlthread_impl.cpp:247
QQmlThread::isThisThread
bool isThisThread() const
Definition
qqmlthread_impl.cpp:252
QQmlThread::shutdown
void shutdown()
Definition
qqmlthread_impl.cpp:206
QQmlThread::waitForNextMessage
void waitForNextMessage()
Definition
qqmlthread_impl.cpp:377
QQmlThread::postMethodToMain
void postMethodToMain(Method &&method, Args &&...args)
Definition
qqmlthread_p.h:140
QQmlThread::restart
void restart()
Definition
qqmlthread_impl.cpp:188
QQmlThread::isParentThread
bool isParentThread() const
Definition
qqmlthread_impl.cpp:257
QQmlThread::callMethodInMain
void callMethodInMain(Method &&method, Args &&...args)
Definition
qqmlthread_p.h:119
QQmlThread::wakeOne
void wakeOne()
Definition
qqmlthread_impl.cpp:242
QQmlThread::startup
void startup()
Definition
qqmlthread_impl.cpp:181
QQmlThread::~QQmlThread
virtual ~QQmlThread()
Definition
qqmlthread_impl.cpp:172
QQmlThread::callMethodInThread
void callMethodInThread(Method &&method, Args &&...args)
Definition
qqmlthread_p.h:126
QQmlThread::threadObject
QObject * threadObject() const
Definition
qqmlthread_impl.cpp:273
QtPrivate
Definition
qalloc.h:29
QT_REQUIRE_CONFIG
QT_REQUIRE_CONFIG(liburing)
QtPrivate::member_function_traits< Return(Object::*)(Args...)>
Definition
qqmlthread_p.h:97
QtPrivate::member_function_traits< Return(Object::*)(Args...)>::class_type
Object class_type
Definition
qqmlthread_p.h:98
QtPrivate::member_function_traits
Definition
qqmlthread_p.h:93
qtdeclarative
src
qml
qml
ftw
qqmlthread_p.h
Generated on
for Qt by
1.18.0