このページについて

場所リスト (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 型であると仮定しています。したがって、常に場所 role にアクセスできると想定されていますが、他の検索結果タイプには場所 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.