장소 목록(QML)
장소 목록 예제에서는 ListView 을 사용하여 장소 목록을 검색하고 표시하는 방법을 보여줍니다.
예제 실행하기
에서 예제를 실행하려면 Qt Creator에서 Welcome 모드를 열고 Examples 에서 예제를 선택합니다. 자세한 내용은 예제 만들기 및 실행하기를 참조하세요.
Places List
예제에서는 특정 지역의 장소 목록을 검색하고 ListView 을 사용하여 결과를 표시하는 방법을 보여줍니다. 이 특정 경우에는 food
이라는 용어와 관련된 장소 검색이 수행됩니다.
장소 검색 수행하기
목록에 장소를 표시하는 QML 애플리케이션을 작성하려면 먼저 다음과 같은 가져오기 선언을 합니다.
import QtQuick import QtPositioning import QtLocation
Plugin 인스턴스를 인스턴스화합니다. Plugin 은 사실상 장소를 소싱하는 백엔드입니다. 플러그인 유형에 따라 몇 가지 필수 매개변수를 입력해야 할 수도 있습니다. 가장 가능성이 높은 PluginParameter 유형은 서비스 플러그인에 문서화되어 있는 서비스 액세스 토큰의 일부 형태입니다. 이 스니펫에서는 추가 매개변수가 필요 없는 osm
플러그인이 사용됩니다:
Plugin { id: myPlugin name: "osm" //specify plugin parameters as necessary //PluginParameter {...} //PluginParameter {...} //... }
다음으로 검색 매개변수를 지정하고 장소 검색 작업을 수행하는 데 사용할 수 있는 PlaceSearchModel 인스턴스를 인스턴스화합니다. 예시를 위해 모델 구성이 완료되면 update()가 호출됩니다. 일반적으로 update()는 버튼 클릭과 같은 사용자 작업에 대한 응답으로 호출됩니다.
PlaceSearchModel { id: searchModel plugin: myPlugin searchTerm: "food" searchArea: QtPositioning.circle(startCoordinate, 5000 /* 5 km radius */); Component.onCompleted: update() }
마지막으로 ListView 을 인스턴스화하여 모델이 찾은 검색 결과를 표시합니다. 인라인 델리게이트가 사용되었으며 모든 검색 결과가 type PlaceSearchesult
이라고 가정했습니다. 따라서 항상 role장소에 액세스할 수 있다고 가정하고 다른 검색 결과 유형에는 role장소가 없을 수 있습니다.
© 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.