关于Qt QObject::sender()函数的一点问题
大风哉 2017-12-13 11:02:35 我在查看QObject* QObject::sender()const的QT文档时有一点疑问,请大家帮忙看看。
这个接口是返回信号发送对象的指针,文档中写了“The pointer is valid only during the execution of the slot that calls this function from this object's thread context.”,这里的“this object”是指接收者对象吗?这句话是不是可以这样理解“这个指针只有在当前接收者对象的线程上下文才有效”?
在下文中“Warning: As mentioned above, the return value of this function is not valid when the slot is called via a Qt::DirectConnection from a thread different from this object's thread. Do not use this function in this type of scenario.”是不是说“当使用Qt::DirectConnection设置信号与槽的模式时,返回的发送者指针是不合法的,因为slot执行时所在线程和signal线程一致,和接收者对象所在线程不同”?
这样就是说这个接口返回的发送者对象指针只有在接收者对象所在线程中执行slot函数过程中才有效?有没有接收者和发送者在同一个线程的情况,如果发生这种情况是不是就是无效了?
QT原文链接:http://doc.qt.io/qt-5/qobject.html#sender