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);
}
そして、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));
}
(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'
それぞれ。
color
を使用してカスタム構造体を正常に登録できましたqRegisterMetaType()
が、uint16_t
とchar*
は構造体またはクラスではないため、これは機能しません。
誰かがそれを行う方法を教えてくれたり、良い代替案を示してくれたりしたら、とてもうれしいです.