Hello!
Some time ago I open this thread to learn how could I call a static method from another thread. Back then I learned about the QMetaObject::invokeMethod which has since served me well.
Now the situation has slightly changed: I call my static method from whatever thread I want and, in that static method, I use QMetaObject::invokeMethod to a call a Singleton class's method:
void MessageFrame::critical(const message &text)
{
if (Q_UNLIKELY
(!QMetaObject::invokeMethod(&instance
(),
"showMessage",Q_ARG
(MessageFrame
::Icon,MessageFrame
::Critical),Q_ARG
(MessageFrame
::message,text
)))) mDebugS("Failed invokeMethod in MessageFrame::critical");
}
void MessageFrame::critical(const message &text)
{
if (Q_UNLIKELY(!QMetaObject::invokeMethod(&instance(),"showMessage",Q_ARG(MessageFrame::Icon,MessageFrame::Critical),Q_ARG(MessageFrame::message,text))))
mDebugS("Failed invokeMethod in MessageFrame::critical");
}
To copy to clipboard, switch view to plain text mode
Everything works fine, but I want to add a new feature: time control. I want to not simply call the static method, but tell it that, after some time, another method of the same Singleton class needs to be called:
void MessageFrame::critical(const message &text, const qint32 time)
{
if (Q_UNLIKELY
(!QMetaObject::invokeMethod(&instance
(),
"showMessage",Q_ARG
(MessageFrame
::Icon,MessageFrame
::Critical),Q_ARG
(MessageFrame
::message,text
)))) mDebugS("Failed invokeMethod in MessageFrame::critical");
if (time > 0)
QTimer::singleShot(time,
&instance
(),
SLOT(nextMessage
()));
}
void MessageFrame::critical(const message &text, const qint32 time)
{
if (Q_UNLIKELY(!QMetaObject::invokeMethod(&instance(),"showMessage",Q_ARG(MessageFrame::Icon,MessageFrame::Critical),Q_ARG(MessageFrame::message,text))))
mDebugS("Failed invokeMethod in MessageFrame::critical");
if (time > 0)
QTimer::singleShot(time,&instance(),SLOT(nextMessage()));
}
To copy to clipboard, switch view to plain text mode
Something like that. The problem is: how can I do this? I have no idea apart from knowing that the above QTimer::singleShot() call don't work.
Momergil
Bookmarks