vault backup: 2025-03-04 11:17:00
This commit is contained in:
9
20.01. Programming/QT/QVariant.md
Normal file
9
20.01. Programming/QT/QVariant.md
Normal file
@@ -0,0 +1,9 @@
|
||||
Qt有許多UI元件都可以另外設定相依的「資料」,例如`QCombobox`,這樣我們就不必老是依賴選項的文字來做許多麻煩的處理。
|
||||
例如,`QCombobox.addItem()`可以夾帶一個`QVariant`,這個`QVariant`就可以夾帶一個pointer。
|
||||
要讓`QVariant`支援`std::shared_ptr`的方式很簡單,只要在你程式的最上方加入你要使用的type就可以,例如,我要支援我自己的class AwSentinelDevice,就這樣寫:
|
||||
```cpp
|
||||
#include <memory>
|
||||
|
||||
Q_DECLARE_SMART_POINTER_METATYPE(std::shared_ptr);
|
||||
Q_DECLARE_METATYPE(std::shared_ptr<AwSentinelDevice>);
|
||||
```
|
||||
Reference in New Issue
Block a user