[英]Boost signals : Connect fails
I have a public method in a C++ class (let's call it classA) which is defined as: 我在C ++类中有一个公共方法(我们称之为classA),该方法定义为:
void someFunction(someOtherCppClassB* arg);
This 'someFunction' method does the following: 此“ someFunction”方法执行以下操作:
theConnection = registerFunction(aPtrToAnInstanceOfCStruct1, boost::bind(&classA::callbackFunction, this, _1));
where 'theConnection' is a private member variable in ClassA and it has the type boost::signals2::connection 其中“ theConnection”是ClassA中的私有成员变量,其类型为boost :: signals2 :: connection
and where 'callbackFunction' is a private method in classA defined as: 其中“ callbackFunction”是classA中的私有方法,定义为:
int callbackFunction(cStruct2** doublePtr);
and where 'aPtrToAnInstanceOfCStruct1' is a pointer to an instance of this C struct: 其中“ aPtrToAnInstanceOfCStruct1”是指向此C结构实例的指针:
typedef struct cStruct1T
{
boost::signals2::signal<int (cStruct2**)> signalVariable;
} cStruct1
and cStruct2 is defined as: 并且cStruct2定义为:
typedef struct cStruct2T
{
/* Variables in this struct */
char someDummyVariable;
} cStruct2
The 'registerFunction' is defined as: “ registerFunction”定义为:
boost::signals2::connection registerFunction(cStruct1* aPtrToAnInstanceOfCStruct1, boost::function<int (cStruct2**)> someCallbackFunction)
{
/* THIS FAILS FOR SOME REASON */
return aPtrToAnInstanceOfCStruct1->signalVariable.connect(someCallbackFunction);
}
For some reason the .connect() generates the following on Android 4.3: 由于某些原因,.connect()在Android 4.3上生成以下内容:
F/libc ( 8556): Fatal signal 11 (SIGSEGV) at 0x0000000c (code=1), thread 8556 F / libc(8556):致命信号11(SIGSEGV)位于0x0000000c(代码= 1),线程8556
I can't figure out what causes the error. 我不知道是什么原因导致了错误。 So I'm hoping that there's a Boost expert out there who can take a look at the code above and tell me what I'm doing wrong.
所以我希望那里有一个Boost专家,他们可以看一下上面的代码,并告诉我我做错了什么。
Thank you. 谢谢。
I'm sorry but I find your example hard to follow. 抱歉,您的榜样很难理解。 But since it compiles, I suspect that you may have a null pointer, judging by the error code.
但是由于它可以编译,因此我可能会根据错误代码判断您是否有一个空指针。
I recommend encapsulating the signals code in the class containing the signal and provide a function to connect your slot
eg: 我建议将信号代码封装在包含信号的类中,并提供连接
slot
的功能,例如:
typedef struct cStruct1T
{
typedef boost::signals2::signal<int (cStruct2**)> SignalTypeName;
SignalTypeName signalVariable;
void connectSlot(const SignalTypeName::slot_type& slot)
{ signalVariable.connect(slot); }
} cStruct1;
You can then register your slot within your someFunction
like this: 然后,您可以像这样在
someFunction
注册插槽:
aPtrToAnInstanceOfCStruct1->connectSlot(boost::bind(&classA::callbackFunction, this, _1));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.