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:

Qt Code:
  1. void MessageFrame::critical(const message &text)
  2. {
  3. if (Q_UNLIKELY(!QMetaObject::invokeMethod(&instance(),"showMessage",Q_ARG(MessageFrame::Icon,MessageFrame::Critical),Q_ARG(MessageFrame::message,text))))
  4. mDebugS("Failed invokeMethod in MessageFrame::critical");
  5. }
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:

Qt Code:
  1. void MessageFrame::critical(const message &text, const qint32 time)
  2. {
  3. if (Q_UNLIKELY(!QMetaObject::invokeMethod(&instance(),"showMessage",Q_ARG(MessageFrame::Icon,MessageFrame::Critical),Q_ARG(MessageFrame::message,text))))
  4. mDebugS("Failed invokeMethod in MessageFrame::critical");
  5.  
  6. if (time > 0)
  7. QTimer::singleShot(time,&instance(),SLOT(nextMessage()));
  8. }
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