Seite 1 von 1

pyotherside qml erste versuche machen Fehler

Verfasst: Freitag 3. Dezember 2021, 19:02
von digi
Moin,

ich möchte eine APP für mein Handy erstellen. Das Handy hat als Betriebssystem Ubuntu Touch von Ubports.
Mit den Tool clickable von Ubports habe ich das grundgerüst für meine APP erstellt.
Das Programm lief so lange bis ich versucht habe einen Button einzufügen :)

Hier das QML File

Code: Alles auswählen

import QtQuick 2.7
import Ubuntu.Components 1.3
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Qt.labs.settings 1.0
import io.thp.pyotherside 1.3

MainView {
    id: root
    objectName: 'mainView'
    applicationName: 'mienimmen.dirk'
    automaticOrientation: true

    width: units.gu(45)
    height: units.gu(75)

    Page {
        anchors.fill: parent

        header: PageHeader {
            id: header
            title: i18n.tr('Mien Immen')
        }
        Label {
            anchors {
                top: header.bottom
                left: parent.left
                right: parent.right
                bottom: parent.bottom
            }
            color: "steelblue"
            text: i18n.tr('Check the logs!')

            verticalAlignment: Label.AlignVCenter
            horizontalAlignment: Label.AlignHCenter
        }
		Rectangle {
					id: rect
					color: "#02d160"
                    radius: 2
                    border.color: "#0f4f02"
                    border.width: 2
                    width: 75
                    height: 25
                    x:  9 
                    y: 9
					Text {
                           id: buttontext
                           text: qsTr("Berechnen")
                           x: parent.x + 4
                           anchors.centerIn:rect
                         }
                    MouseArea{
                               anchors.fill: parent
                               onEntered: {
                                   addImportPath(Qt.resolvedUrl('../src/'));
                                            importModule('example', function() {
                                                    python.call('example.speak', ['moin'], function(returnValue) {
                                                    console.log('example.speak returned ' + returnValue);
                                                     })
                                                });

                                            }
                               }
		 }//Rectangle  
    }

    Python {
        id: python

        Component.onCompleted: {
                                addImportPath(Qt.resolvedUrl('../src/'));

                                importModule('example', function() {
                                console.log('module imported');
                                python.call('example.speak', ['Hello World!'], function(returnValue) {
                                                console.log('example.speak returned ' + returnValue);
                                             })
                                });
        }

        onError: {
            console.log('python error: ' + traceback);
        }
    }
}

und hier das Python File

Code: Alles auswählen

def speak(text):
    print(text)
    return text

def test(text):
	print ("test")

Folgende Fehler bekomme ich
file:///home/dirk/Projekte/clickable/mienimmen/mienimmen/build/all/app/install/qml/Main.qml:72: ReferenceError: addImportPath is not defined

Zeile 72 ist addImportPath(Qt.resolvedUrl('../src/'));

LG Dirk

Re: pyotherside qml erste versuche machen Fehler

Verfasst: Freitag 3. Dezember 2021, 19:28
von __deets__
Meine QML-Zeiten liegen lange zurück. Aber onComoleted ist ggf einfach zu früh. Pack das doch mal in das click event.