[SOLVED] QMetaObject::invokeMethod with boost::shared_ptr argument
-
@
Q_DECLARE_METATYPE(boost::shared_ptrMy::Class)void function()
{
auto val = QMetaObject::invokeMethod(this->m_object->sender, "senderFunction", Qt::AutoConnection, Q_ARG(boost::shared_ptrMy::Class, this->m_myClass));
}
@When running my app, Qt reports "No such method"
Am I doing something wrong here?
senderFunction() is an inherited function which sender has public access to from the base class. Is this causing the problem?
-
Hi,
Unless you really want your function to be a a slot, there's also the Q_INVOKABLE keyword, the end effect is the same but it makes your code clearer.
-
So while Q_INVOKABLE will work, it does not solve my main issue. Many of my widgets inherit from a non-qt base class. This class is capable of setting a pointer to my kernel.
@
class WidgetBase
{
public:
void setKernel(Kernel* x);
};
@So in effect, all of my widgets are able to set the kernel. The problem is I need to be able to set these kernels on a separate thread from the widgets I have created.
As far as I can tell, WidgetBase would have to inherit from Q_Object so that I could set "setKernel" as Q_INVOKABLE. Now WidgetBase inherits from Q_Object and I can no longer inherit from WidgetBase with any of my custom widgets. This is also true declaring as slots.
@
class WidgetBase : public Q_Object
{
Q_OBJECT
public:
Q_INVOKABLE void setKernel(Kernel* x);
};
@Is my only option to not inherit from WidgetBase and have every custom widget i've created so far run their own setKernel() function?
-
Not their own. But you would need first to make it virtual and for the widgets that uses it, you need to reimplement it (adding the Q_INVOKABLE keyword in the declaration) and just call the base class implementation.