PTT/ERROR_FIX_LOG.md

52 lines
1.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 错误修复总结
## 问题描述
运行程序时出现 `NameError: name 'QWidget' is not defined` 错误。
### 错误堆栈
```
File "D:\production_test_tool\src\ui\login_dialog.py", line 33, in setup_ui
content_widget = QWidget()
^^^^^^^
NameError: name 'QWidget' is not defined
```
## 根本原因
在修改 [login_dialog.py](login_dialog.py) 的布局时,将 `QLabel()` 改为 `QWidget()`,但是 `QWidget` 未在文件的导入部分声明。
### 之前的导入:
```python
from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit,
QPushButton, QMessageBox, QCheckBox, QApplication, QSpacerItem, QSizePolicy
)
```
## 解决方案
在导入列表中添加 `QWidget`
```python
from PyQt5.QtWidgets import (
QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit,
QPushButton, QMessageBox, QCheckBox, QApplication, QSpacerItem, QSizePolicy,
QWidget # ← 新增
)
```
## 修复验证
✓ 文件编译成功 (py_compile)
✓ 导入测试成功
✓ UI 模块导入成功
## 修改文件
- [src/ui/login_dialog.py](src/ui/login_dialog.py) - 第 7 行添加 `QWidget` 导入
## 当前状态
所有 UI 文件现在都可以正常导入和使用,程序应该能正常启动。