이 페이지에서

장소 목록 (QML)

'장소 목록' 예제는 ListView 를 사용하여 장소를 검색하고 목록으로 표시하는 방법을 보여줍니다.

주소가 포함된 피자 가게 목록 (번호 매김)

예제 실행

다음 위치에서 예제를 실행할 수 있습니다:

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 유형이라고 가정했습니다. 따라서 항상 place role 에 접근할 수 있다고 가정하지만, 다른 검색 결과 유형의 경우 place role 가 없을 수도 있습니다.

ListView {
    anchors.fill: parent
    model: searchModel
    delegate: Component {
        Row {
            spacing: 5
            Marker { height: parent.height }
            Column {
                Text { text: title; font.bold: true }
                Text { text: place.location.address.text }
            }
        }
    }
}

예제 프로젝트 @ code.qt.io

© 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.