修复Config类成员修改后无法保存到config.json的问题 #865
Closed
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题背景
在使用串口时,由于经常要插拔串口,导致串口数量总是不固定
![屏幕截图 2024-05-04 005655](https://private-user-images.githubusercontent.com/133895541/327828051-2a55b453-6b00-4f04-b31e-e57ef4104876.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3MjcyMzUsIm5iZiI6MTczOTcyNjkzNSwicGF0aCI6Ii8xMzM4OTU1NDEvMzI3ODI4MDUxLTJhNTViNDUzLTZiMDAtNGYwNC1iMzFlLWU1N2VmNDEwNDg3Ni5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNlQxNzI4NTVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05YTFmMjQ2MjM5YTdiZTdjNGMxOGY2MzU4ODM0NjlhOThjYWYwZTMyNjAwYjUxYzU4NDRiMDNjZWY2NTkyYmY1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.pSm1n4hgkQBSZGRDPpf2VzVIiD4CfJVkIOsC0rKObWE)
在这个背景下,我需要使用ComboBoxSettingCard,并在下框被点击时重新获取所有串口
业务代码
问题描述
当串口数量变化且用以上代码刷新后,之后再当
COMCard
下拉框选中的值改变时,不能将值保存到config.json
中##原因分析
cfg.port = OptionsConfigItem("Serial", "COM", "COM3", OptionsValidator(cfg.portList))
,为cfg.port
重新赋值config.json
时调用了qfluentwidgets\common\config.py
中QConfig
类的toDict
方法,其中用以下代码读取类成员的值.__class__
导致读取类成员的值时,读到的是cfg.port重新赋值之前的值,原因我不知道解决方法
去掉
.__class__
去掉后功能正常,但暂不清楚是否有其他影响