SignalSpy QML Type
신호 발신에 대한 인트로스펙션을 활성화합니다. 더 보기...
| Import Statement: | import QtTest |
| Inherits: |
속성
- count : int
- signalArguments : list
- signalName : string
- target : object
- valid : bool
방법
자세한 설명
다음 예제에서는 사용자 정의 Button 유형의 "clicked" 신호를 감시하기 위해 SignalSpy가 설치됩니다. 신호가 발생하면 스파이의 count 속성 값이 증가합니다.
Button {
id: button
SignalSpy {
id: spy
target: button
signalName: "clicked"
}
TestCase {
name: "ButtonClick"
function test_click() {
compare(spy.count, 0)
button.clicked();
compare(spy.count, 1)
}
}
}위와 같은 테스트 방식은 동기식으로 발생되는 신호에 적합합니다. 비동기식 신호의 경우, ` wait()` 메서드를 사용하여 신호가 발생할 때까지(또는 타임아웃이 만료될 때까지) 테스트를 차단할 수 있습니다.
속성 설명서
count : int [read-only]
이 속성은 clear()이 마지막으로 호출된 이후 target 에서 signalName 가 전송된 횟수를 정의합니다.
target, signalName 및 clear()도 참조하십시오 .
signalArguments : list [read-only]
이 속성은 발신된 신호의 인자 목록을 보관합니다. 신호가 발신될 때마다 해당 신호의 인자를 포함하는 항목 하나가 목록 끝에 추가됩니다. 새로운 target 또는 signalName 에 연결하거나 clear() 메서드를 호출하면 signalArguments는 비워집니다.
signalName 및 clear()도 참조하십시오 .
signalName : string
이 속성은 target 에서 수신 대기할 신호의 이름을 정의합니다.
target : object
이 속성은 ` signalName ` 신호의 발신을 수신하는 데 사용될 대상 객체를 정의합니다.
signalName 및 count도 참조하십시오 .
valid : bool [read-only]
이 속성은 현재 신호 연결 상태를 나타냅니다. target 의 signalName 가 성공적으로 연결된 경우 true가 되고, 그렇지 않은 경우 false가 됩니다.
count, target, signalName 및 clear()도 참조하십시오 .
메서드 문서
clear()
count 의 값을 0 으로, signalArguments 의 값을 비워줍니다. valid 에는 영향을 미치지 않습니다.
wait(timeout = 5000)
target 에서 signalName 신호가 발생하기를 최대 timeout 밀리초 동안 대기합니다. 신호가 발생하지 않으면 테스트 케이스가 실패합니다.
SignalSpy {
id: spy
target: button
signalName: "clicked"
}
function test_async_click() {
...
// do something that will cause clicked() to be emitted
...
spy.wait()
compare(spy.count, 1)
}두 가지 가능한 시나리오가 있습니다. wait()가 호출될 때 신호가 이미 발생했을 경우와, 신호가 아직 발생하지 않았을 경우입니다. wait() 함수는 신호가 이미 발생했을 경우 즉시 반환함으로써 첫 번째 시나리오를 처리합니다.
clear() 메서드를 사용하면 이미 발생한 신호에 대한 정보를 제거하여 wait()를 향후 신호 발생과 동기화할 수 있습니다.
clear() 및 TestCase::tryCompare()도 참조하십시오 .
© 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.