Qt signal transmission slot structure of the custom

Preface:

Normally we use and the type of signal c ++ groove defined parameters inside are possible qt

But to pass a custom structure to how to get?

If you do not register, then compiled a direct connection is not being given the time to perform the error will not take effect

struct my_Custom
{
	...
	...
	...
	
}
  1. Sign up what this structure in the structure below
    Q_DECLARE_METATYPE (my_Custom)

  2. Add headers #include <QMetaType>

  3. Was added over a qRegisterMetaType connect connection <my_Custom> ( "my_Custom");

    connect (A,&AA::signal(my_Custom),B,&BB::slot(my_Custom))

This can be registered on the qt know what your body structure or else he did not know the signal can not be connected to the slot according to the parameters

Published 171 original articles · won praise 386 · views 160 000 +

Guess you like

Origin blog.csdn.net/weixin_42837024/article/details/104946250