Qt for Python 애플리케이션 디버그
디버그파이와 QML 디버거를 사용하여 Python과 QML 코드가 모두 포함된 Python 애플리케이션을 디버깅할 수 있습니다.
Python 코드 디버그하기
애플리케이션의 Qt for Python 코드만 디버깅하려면 VS Code의 지침을 따르세요: VS 코드에서 Python 디버깅의 지침을 따르세요.
Qt for Python 애플리케이션을 시작하고 디버그하려면 다음과 같이 하세요:
- launch.json 파일을 엽니다. 자세한 내용은 Qt 애플리케이션 디버그를 참조하세요.
- Python Debugger 을 선택합니다.
- Add Configuration 을 선택한 다음 Qt: PySide: Launch 디버그 구성을 선택합니다.
구성은 다음과 같습니다:
"configurations": [
Pyside
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Qt: PySide: Launch",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/main.py",
"preLaunchTask": "PySide: build"
}
]참고: main.py 이 애플리케이션 진입점이 아닌 경우 "program" 에서 변경합니다.
Python 및 QML 혼합 코드 디버그
먼저 애플리케이션을 시작한 다음 Qt: Acquire Port 실행 전 작업에서 획득한 포트 번호를 사용하여 debugpy 및 QML 디버거를 모두 연결하는 디버그 구성을 만들 수 있습니다.
QML 디버깅 켜기
QML 디버깅을 사용 설정하려면 다음 코드를 QML 애플리케이션에 추가합니다:
from pathlib import Path
from argparse import ArgumentParser
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine, QQmlDebuggingEnabler
if __name__ == "__main__":
argument_parser = ArgumentParser()
argument_parser.add_argument("-qmljsdebugger", action="store",
help="Enable QML debugging")
options = argument_parser.parse_args()
if options.qmljsdebugger:
QQmlDebuggingEnabler.enableDebugging(True)
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()애플리케이션 실행 및 디버그
QML 디버거는 QmlEngine 인스턴스가 실행하는 소켓 서버에 연결됩니다. 실행 구성에서 포트 번호를 지정합니다.
Python 및 QML 코드가 모두 포함된 Qt Quick 애플리케이션을 디버깅하려면 다음과 같이 하세요:
- launch.json 파일을 엽니다. 자세한 내용은 Qt 애플리케이션 디버그를 참조하세요.
- Python Debugger 을 선택합니다.
- Add Configuration 을 선택한 다음 Qt: PySide: Launch with QML Debugger 디버그 구성을 선택합니다.
args에서"port"값을 사용할 포트 번호로 설정합니다:"configurations": [ { "name": "Qt: PySide: Launch with QML debugger", "type": "debugpy", "request": "launch", "program": "${workspaceFolder}/main.py", "preLaunchTask": "PySide: build", "args": [ "-qmljsdebugger=port:<port_number>,block,services:DebugMessages,QmlDebugger,V8Debugger" ]- Add Configuration 을 선택한 다음 Qt: QML: Attach by port 디버그 구성을 선택합니다.
- launch.json 파일에서 포트 번호를
port옵션의 값으로 설정합니다:"configurations": [ { "name": "Qt: QML: Attach by port", "type": "qml", "request": "attach", "host": "localhost", "port": "<port_number>" }, - Python/QML 디버깅을 위한 복합 실행 작업을 launch.json 파일에 추가합니다:
"compounds": [ { "name": "Python/QML", "configurations": [ "Qt: PySide: Launch with QML debugger, "Qt: QML: Attach by port" ] } ] - 복합 디버그 구성을 실행합니다.
포트 번호 자동 할당
${command:qt-qml.debugPort} 변수와 복합 실행 및 사전 실행 작업을 사용하여 포트 번호를 자동으로 할당하세요:
"configurations": [
{
"name": "Qt: PySide: Launch with QML debugger",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/main.py",
"preLaunchTask": "PySide: build",
"args": [
"-qmljsdebugger=port:${command:qt-qml.debugPort},block,services:DebugMessages,QmlDebugger,V8Debugger"
]
},
{
"name": "Qt: QML: Attach by port",
"type": "qml",
"request": "attach",
"host": "localhost",
"port": "${command:qt-qml.debugPort}"
},
],
"compounds": [
{
"name": "Python/QML",
"configurations": [
"Qt: PySide: Launch with QML debugger,
"Qt: QML: Attach by port"
],
"preLaunchTask": "Qt: Acquire Port",
}
]Qt 애플리케이션 디버그, Qt Quick 애플리케이션 디버그, VS Code: 디버깅 및 VS Code:VS Code에서 파이썬 디버깅을 참조하세요.
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.