Qt for Python 애플리케이션 디버깅
debugpy와 QML 디버거를 사용하여 Python 코드와 QML 코드가 모두 포함된 Python 애플리케이션을 디버그할 수 있습니다.
Python 코드 디버깅
애플리케이션에서 Qt for Python 코드만 디버그하려면 VS Code: VS Code에서 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>" }, - launch.json 파일에 Python/QML 디버깅을 위한 복합 실행 태스크를 추가합니다:
"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에서 Python 디버깅.
© 2026 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.