1. 程式人生 > >QT槽函式獲取訊號傳送物件

QT槽函式獲取訊號傳送物件

## Qt 在槽函式中獲取訊號傳送物件 Qt中提供了一個函式 qobject_cast(QObject *object),可以通過這個函式判斷訊號發出物件 >Qt 幫助文件的解釋: Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns nullptr. If object is nullptr then it will also return nullptr. The class T must inherit (directly or indirectly) QObject and be declared with the Q_OBJECT macro. A class is considered to inherit itself. The qobject_cast() function behaves similarly to the standard C++ dynamic_cast(), with the advantages that it doesn't require RTTI support and it works across dynamic library boundaries. + 簡單來說 就是使用這個函式會得到你轉型的的一個例項,但是這個類必須繼承自QObject 或者其子類並且宣告Q_OBJECT 這個巨集 + QT 幫助文件中一個Example ``` QObject *obj = new QTimer; QTimer *timer = qobj