1

i created an app in qt creator that displays a simple map and i want to do the same in pyside project without using webengine. this is my code in qml:

import QtQuick 2.0
import QtPositioning 5.5
import QtLocation 5.6
import QtQuick.Controls 2.0

Item
{
id: root
visible: true

Plugin
{
    id: osmPlug
    name: "osm"
    
    PluginParameter
    {
        name: "osm.mapping.providersrepository.disabled"
        value: "true"
    }
    PluginParameter
    {
        name: "osm.mapping.providersrepository.address"
        value: "http://maps-redirect.qt.io/osm/5.6/"
    }
}

Map
{
    id: map
    anchors.fill: parent
    plugin: osmPlug
    center: QtPositioning.coordinate(59.91, 10.75) // Oslo
    zoomLevel: 3
    copyrightsVisible: false
    fieldOfView: 15
}
}

this code in a pyside project ( in qtcreator ) returns this error: module "QtLocation" is not installed

python code:

# This Python file uses the following encoding: utf-8
import sys
from pathlib import Path

from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine


if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
qml_file = Path(__file__).resolve().parent / "main.qml"
engine.load(qml_file)
if not engine.rootObjects():
    sys.exit(-1)
sys.exit(app.exec())

how can i solve this problem?

Thanks in advance

EDIT:

''' answer in comments '''

user17312099
  • 11
  • 1
  • 3
  • With Qt6.x the version numbers are no longer needed on imports. The earlier Qt6.0 versions didn't have QtLocation, but, that is something I think either is coming are already fixed in later versions. So (1) remove the version numbers from your imports, (2) keep your installation up to date with the latest patches, (3) if it isn't working today, try again in a few months time. – Stephen Quan Dec 09 '22 at 12:09
  • thanks for your help. but i am using qt 5.15.2 and the code runs in Qt Quick Project but not in pyside project ): – user17312099 Dec 09 '22 at 19:56
  • But you are using PySide6 which is based on Qt6, not Qt5.15.2. I don't know which version of PySide6 you're using, but, if it's Qt6, the first thing you can do is delete the version numbers from your imports. i.e. try `import QtLocation` instead of `import QtLocation 5.6` – Stephen Quan Dec 09 '22 at 20:55
  • Nice (: . i changed pyside version from 6 to 2 and now it works. thank you Stephen – user17312099 Dec 10 '22 at 10:21

0 Answers0