我想使用QMetaObject :: invokeMethod()从不同的线程异步调用一个插槽
包含槽的类声明为:
class Paintable : public QObject {
Q_OBJECT
[...]
public slots:
void drawString(uint16_t x, uint16_t y, uint16_t size, const char* str, color c);
}
Run Code Online (Sandbox Code Playgroud)
调用invokeMethod的方法定义为:
void drawStringAsynchronously(uint16_t x, uint16_t y, uint16_t size, const char* str, color c) {
QMetaObject::invokeMethod(paintable,
"drawString",
Qt::QueuedConnection,
Q_ARG(uint16_t, x), Q_ARG(uint16_t, y), Q_ARG(uint16_t, size),
Q_ARG(const char*, str), Q_ARG(color, c));
}
Run Code Online (Sandbox Code Playgroud)
(哪里paintable是类型Paintable*)
但Qt似乎无法在invokeMethod中使用uint16_t或char*,因为在运行时我收到以下消息:
QMetaMethod::invoke: Unable to handle unregistered datatype 'const char*'
和
QMetaMethod::invoke: Unable to handle unregistered datatype 'uint16_t' …