SignalSpy QML Type
신호 방출에 대한 인트로스펙션을 지원합니다. 더 보기...
Import Statement: | import QtTest |
Inherits: |
속성
- count : int
- signalArguments : list
- signalName : string
- target : object
- valid : bool
방법
상세 설명
다음 예시에서는 사용자 정의 버튼 유형에서 "클릭" 신호를 감시하기 위해 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 |
이 속성은 clear()에 대한 마지막 호출 이후 target 에서 signalName 가 전송된 횟수를 정의합니다.
target, signalName, 및 clear()도 참조하세요 .
signalArguments : list |
이 프로퍼티는 방출된 신호 인수의 목록을 보유합니다. 신호가 방출될 때마다 신호의 인수가 포함된 항목이 목록에 하나씩 추가됩니다. 새 target 또는 새 signalName 에 연결하거나 clear() 메서드를 호출하면 signalArguments가 비어 있는 것으로 재설정됩니다.
signalName 및 clear()도 참조하세요 .
target : object |
이 속성은 signalName 신호의 방출을 수신하는 데 사용할 대상 객체를 정의합니다.
signalName 및 count도 참조 하세요.
valid : bool |
이 속성은 현재 신호 연결 상태를 정의합니다. target 의 signalName 가 성공적으로 연결되면 참이 되고, 그렇지 않으면 거짓이 됩니다.
count, target, signalName, clear()도 참조하세요 .
메서드 문서
clear() |
count 을 0으로 지우고 valid 을 거짓으로 재설정하며 signalArguments 을 비워둡니다.
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()도 참조하세요 .
© 2025 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.