QMetaObject::invokeMethod does not call slot

217 views Asked by At

I have a public signal called UpdateScreenshots in the workspacemanager class that takes screenshots of some widgets. It then returns these screenshots in a struct I've defined. This call is made from a thread as taking screenshots can apparently only be done on the main thread. However, this invokemethod call is not working and the updatescreenshots slot is not being called. What could I be doing wrong? Is there a better way to do this?

invokeMethod call

VmsWorkspaceManager::InfoStruct info;

QMetaObject::invokeMethod(m_Manager, "UpdateScreenshots", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(Vms::GuiWidgets::VmsWorkspaceManager::InfoStruct, info));

The definition of the slot;

public slots:

/**
* \brief Updates the current screenshots to be sent to a remote client
*/
InfoStruct UpdateScreenshots() const;

1

There are 1 answers

0
p-a-o-l-o On BEST ANSWER

First, make sure you have this declaration at the bottom of the InfoStruct header:

Q_DECLARE_METATYPE(Vms::GuiWidgets::VmsWorkspaceManager::InfoStruct)

Then, on top of your main function, have this call:

int main(int argc, char *argv[])
{
    qRegisterMetaType<Vms::GuiWidgets::VmsWorkspaceManager::InfoStruct>("Vms::GuiWidgets::VmsWorkspaceManager::InfoStruct");

Since you're using namespaces, you must be very consistent with them, so be sure the slot signature is like this:

Vms::GuiWidgets::VmsWorkspaceManager::InfoStruct UpdateScreenshots() const;