Connections and functions don't work in Ubuntu Mate
-
I'm using Ubuntu Mate 20.04.5 and Qt version 5.12.8 in a mini-computer Odroid N2. The same project works fine in my computer with normal Ubuntu, but in the Mate Version, the values from backend defined by function doesn't update in frontend. Both are using Pyside2.
In main.py I have:
temped = 37
setTempED = Signal(str)[...]
temped = randint(35, 40)
self.setTempED.emit(str(temped))And in the .qml file I have:
Text { id: tempEDLabel x: 531 y: 135 width: 62 height: 38 text: qsTr("37") anchors.left: parent.left anchors.top: parent.top font.pixelSize: 31 horizontalAlignment: Text.AlignHCenter font.styleName: "Medium" anchors.leftMargin: 562 anchors.topMargin: 239 Connections { target: backend function setTempED(temp1) { tempEDLabel.text = temp1 } } }
When I play the program in Ubuntu Mate, the random values (randint) don't appear in frontend, it stays fixed in 37. But in normal Ubuntu it varies between 35,40 . Thanks for any help!
-
Hi,
Please provide a minimal runnable example so people can test your issue.
Which version of PySide2 are you using ?
How did you install it ? -
Can you also post a minimal script that shows your issue ?
-
@SGaist This is a project university, and the Odroid stays in the university. I can post a video with the project working OK in my computer:
https://drive.google.com/file/d/1YCuwCvj6ggn6B41DrdOlN-W04cUrwvlI/view?usp=share_link
As I had said, in normal Ubuntu the values update, but in Ubuntu Mate, they stayed fixed.
-
The full main.py:
# This Python file uses the following encoding: utf-8 import os from pathlib import Path import sys import datetime from PySide2.QtGui import QGuiApplication from PySide2.QtQml import QQmlApplicationEngine from PySide2.QtCore import QObject, Slot, Signal, QTimer from random import seed from random import randint #PayloadScreen payload = 0 target = 252 payloadstate = "Loading" #MonitorScreen airtemp = 26 enginespeed = 1800 systemairpressure = 1035 systemvoltage = 23 #Brake temped = 30 tempet = 35 tempdd = 37 tempdt = 39 pressbomb = 937 velbomb = 0 temparcabine = 29.6 tempardctcabine = 28 tempoleo = 39 temparcasol = 10 proleoET = 60 proleoDT = 9 posretard = 0 pressacumsec = 18697 pospedalsec = 0 pospedalserv = 0 pressacumserv = 15143 #Chassi presslubauto = 101 angulobascula = 41 nivelcomb = 65 pressoleoacu = 21426 tempfludir = 43 pressoleobombadir = 21603 #Transmissão velocidade = 0 tempoleoconvtorq = 25 totalhrs = 15004 tempoleotrans = 26 distancia = 177858 #Motor posacelerador = 0 rotdesejada = 500 temparambiente = 23 pressaoatmosferica = 92 pressarcarter = 0 pressabssdarref = 155 templiquidoarref = 44 fatorcarga = 7 pressdifoleo = 34 pressaoleo = 533 pressaoleoabs = 625 tempoleo = 46 rotacao = 696 tempescapeLE = 164 tempescapeLD = 163 pressabsdbm = 213 pressdifiltro = 10 presscomb = 611 admbombcomb = 107 presscremalheiracomb = 81000 tempcremalheiracomb = 36 tempcomb = 31 presscoletoradm2 = -1 tempcoletoradm2 = 31 presscoletoradm1 = 0 tempcoletadm = 31 entrcmpturbo = 91.97 nivelliquidoarref = "Baixo" presscombnfiltr = 700 #VIMS pesoacum = 603465 distpercarregado = 107888 tempviagem = 5431 contotalcarga = 24661 derivpicoarm = 712 passopicoarm = 2499 inclpico = -273 pressaoesteioDE = 2903 pressaoesteioTE = 1794 pressaoesteioDD = 2677 pressaoesteioTD = 1336 tempopercurso = 101103 class MainWindow(QObject): def __init__ (self): QObject.__init__(self) self.timer = QTimer() self.timer.timeout.connect(lambda: self.updateTimer()) self.timer.start(750) setTimeValue = Signal(str) setDateValue = Signal(str) setCurrentGear = Signal(str) setPayloadValue = Signal(str) setPayloadState = Signal(str) setTargetValue = Signal(str) setAirTempValue = Signal(str) setEngineSpeedValue = Signal(str) setSystemAirPressureValue = Signal(str) setSystemVoltageValue = Signal(str) setMaxGearState = Signal(str) setTransmissionCurrentPositionState = Signal(str) setMaxGear = Signal(str) setTempED = Signal(str) setTempET = Signal(str) setTempDD = Signal(str) setTempDT = Signal(str) setPressBomb = Signal(str) setVelBomb = Signal(str) setTempAirCabin = Signal(str) setTempAirDctCabin = Signal(str) setTempOleoEixoDif = Signal(str) setTempArCabSol = Signal(str) setPrOleoET = Signal(str) setPrOleoDT = Signal(str) setPosRetard = Signal(str) setPressAcumSec = Signal(str) setPosPedalSec = Signal(str) setPosPedalServ = Signal(str) setPressAcumServ = Signal(str) setPressLubAuto = Signal(str) setAnguloBascula = Signal(str) setNivelComb = Signal(str) setPressOleoDir = Signal(str) setTempFluidDir = Signal(str) setPressOleoBombaDir = Signal(str) setVelocidade = Signal(str) setTempOleoConvTrq = Signal(str) setTempOleoTrans = Signal(str) setDistance = Signal(str) setTotalHrs = Signal(str) setPosAcelerador = Signal(str) setRotacaoDesej = Signal(str) setTempArAmb = Signal(str) setPressAtm = Signal(str) setPressArCarter = Signal(str) setPressAbsArref = Signal(str) setTempArref = Signal(str) setFatorCarga = Signal(str) setPressDifOleo = Signal(str) setPressOleoMtr = Signal(str) setPressOleoMtrAbs = Signal(str) setTempOleoMtr = Signal(str) setRotacao = Signal(str) setTempEscapeLE = Signal(str) setTempEscapeLD = Signal(str) setPressSDBMtrc = Signal(str) setPressDifFiltro = Signal(str) setPressComb = Signal(str) setAdmBombComb = Signal(str) setPressCremComb = Signal(str) setTempCremComb = Signal(str) setTempComb = Signal(str) setPressColAdm2 = Signal(str) setTempColAdm2 = Signal(str) setTempColetAdm = Signal(str) setEntrCmpTurbo = Signal(str) setNivelArref = Signal(str) setPressCombNFiltr = Signal(str) setPesoAcum = Signal(str) setDistPerCarr = Signal(str) setTempViagem = Signal(str) setContTotalCarga = Signal(str) setDerivPicoArm = Signal(str) setPassoPicoArm = Signal(str) setInclPico = Signal(str) setPressEsteioDE = Signal(str) setPressEsteioTE = Signal(str) setPressEsteioDD = Signal(str) setPressEsteioTD = Signal(str) setTempPercurso = Signal(str) def updateTimer(self): global payload global payloadstate global target global airtemp global enginespeed global systemairpressure global systemvoltage global temped global tempet global tempdd global tempdt global pressbomb global velbomb global temparcabine global tempardctcabine global tempoleo global temparcasol global proleoET global proleoDT global posretard global pressacumsec global pospedalsec global pospedalserv global pressacumserv global presslubauto global angulobascula global nivelcomb global pressoleoacu global tempfludir global pressoleobombadir global velocidade global tempoleoconvtorq global totalhrs global tempoleotrans global distancia global posacelerador global rotdesejada global temparambiente global pressaoatmosferica global pressarcarter global pressabssdarref global templiquidoarref global fatorcarga global pressdifoleo global pressaoleo global pressaoleoabs global tempoleo global rotacao global tempescapeLE global tempescapeLD global pressabsdbm global pressdifiltro global presscomb global admbombcomb global presscremalheiracomb global tempcremalheiracomb global tempcomb global presscoletoradm2 global tempcoletoradm2 global presscoletoradm1 global tempcoletadm global entrcmpturbo global nivelliquidoarref global presscombnfiltr global pesoacum global distpercarregado global tempviagem global contotalcarga global derivpicoarm global passopicoarm global inclpico global pressaoesteioDE global pressaoesteioTE global pressaoesteioDD global pressaoesteioTD global tempopercurso now = datetime.datetime.now() formatTime = now.strftime("%H:%M:%S") formatDate = now.strftime("%d/%m/%Y") self.setTimeValue.emit(formatTime) self.setDateValue.emit(formatDate) self.setCurrentGear.emit("2") #PayloadScreen self.setPayloadValue.emit(str(payload)) self.setTargetValue.emit(str(target)) self.setPayloadState.emit(str(payloadstate)) payload = payload + 10 if payload < target: payloadstate = "Carregando" if payload == target: payloadstate = "Carregado" if payload > target: payloadstate = "Sobrecarga" #MonitorScreen self.setAirTempValue.emit(str(airtemp)) self.setEngineSpeedValue.emit(str(enginespeed)) self.setSystemAirPressureValue.emit(str(systemairpressure)) self.setSystemVoltageValue.emit(str(systemvoltage)) airtemp = randint(24, 27) enginespeed = randint(1800, 2000) systemairpressure = randint(1000, 1500) systemvoltage = randint(22, 24) #Brake self.setTempED.emit(str(temped)) self.setTempET.emit(str(tempet)) self.setTempDD.emit(str(tempdd)) self.setTempDT.emit(str(tempdt)) self.setPressBomb.emit(str(pressbomb)) self.setVelBomb.emit(str(velbomb)) self.setTempAirCabin.emit(str(temparcabine)) self.setTempAirDctCabin.emit(str(tempardctcabine)) self.setTempOleoEixoDif.emit(str(temped)) self.setTempArCabSol.emit(str(tempet)) self.setPrOleoET.emit(str(tempdd)) self.setPrOleoDT.emit(str(tempdt)) self.setPosRetard.emit(str(posretard)) self.setPressAcumSec.emit(str(pressbomb)) self.setPosPedalSec.emit(str(pospedalsec)) self.setPosPedalServ.emit(str(pospedalserv)) self.setPressAcumServ.emit(str(pressacumserv)) temped = randint(35,40) tempet = randint(35,40) tempdd = randint(35, 40) tempdt = randint(35, 40) pressbomb = randint(800, 1000) temparcabine = randint(25, 40) tempardctcabine = randint(25, 40) tempoleo = randint(35, 40) temparcasol = randint(8, 10) proleoET = randint(50, 100) proleoDT = randint(50, 100) posretard = randint(0, 100) pressacumsec = randint(17000, 20000) pospedalsec = randint(0, 100) pospedalserv = randint(0, 100) pressacumserv = randint(15000, 18000) #Chassi self.setPressLubAuto.emit(str(presslubauto)) self.setAnguloBascula.emit(str(angulobascula)) self.setNivelComb.emit(str(nivelcomb)) self.setPressOleoDir.emit(str(pressoleoacu)) self.setTempFluidDir.emit(str(tempfludir)) self.setPressOleoBombaDir.emit(str(pressoleobombadir)) presslubauto = randint(0, 200) angulobascula = randint(0, 90) nivelcomb = randint(0, 100) pressoleoacu = randint(18000, 22000) tempfludir = randint(35, 45) pressoleobombadir = randint(18000, 22000) #Transmissão self.setVelocidade.emit(str(velocidade)) self.setTempOleoConvTrq.emit(str(tempoleoconvtorq)) self.setTotalHrs.emit(str(totalhrs)) self.setTempOleoTrans.emit(str(tempoleotrans)) self.setDistance.emit(str(distancia)) velocidade = randint(0, 50) tempoleoconvtorq = randint(25, 40) tempoleotrans = randint(25, 40) distancia = randint(0, 20000) totalhrs = totalhrs + 1 #Motor self.setPosAcelerador.emit(str(posacelerador)) self.setRotacaoDesej.emit(str(rotdesejada)) self.setTempArAmb.emit(str(temparambiente)) self.setPressAtm.emit(str(pressaoatmosferica)) self.setPressArCarter.emit(str(pressarcarter)) self.setPressAbsArref.emit(str(pressabssdarref)) self.setTempArref.emit(str(templiquidoarref)) self.setFatorCarga.emit(str(fatorcarga)) self.setPressDifOleo.emit(str(pressdifoleo)) self.setPressOleoMtr.emit(str(pressaoleo)) self.setPressOleoMtrAbs.emit(str(pressaoleoabs)) self.setTempOleoMtr.emit(str(tempoleo)) self.setRotacao.emit(str(rotacao)) self.setTempEscapeLE.emit(str(tempescapeLE)) self.setTempEscapeLD.emit(str(tempescapeLD)) self.setPressSDBMtrc.emit(str(pressabsdbm)) self.setPressDifFiltro.emit(str(pressdifiltro)) self.setPressComb.emit(str(presscomb)) self.setAdmBombComb.emit(str(admbombcomb)) self.setPressCremComb.emit(str(presscremalheiracomb)) self.setTempCremComb.emit(str(tempcremalheiracomb)) self.setTempComb.emit(str(tempcomb)) self.setPressColAdm2.emit(str(presscoletoradm2)) self.setTempColAdm2.emit(str(tempcoletoradm2)) self.setTempColetAdm.emit(str(tempcoletadm)) self.setEntrCmpTurbo.emit(str(entrcmpturbo)) self.setNivelArref.emit(str(nivelliquidoarref)) self.setPressCombNFiltr.emit(str(presscombnfiltr)) posacelerador = randint(0, 100) rotdesejada = randint(0, 1000) temparambiente = randint(15, 40) pressaoatmosferica = randint(90, 95) pressarcarter = randint(0, 10) pressabssdarref = randint(50, 200) templiquidoarref = randint(30, 60) fatorcarga = randint(0, 100) pressdifoleo = randint(20, 100) pressaoleo = randint(0, 600) pressaoleoabs = randint(100, 700) tempoleo = randint(0, 60) rotacao = randint(0, 1000) tempescapeLE = randint(150, 200) tempescapeLD = randint(150, 200) pressabsdbm = randint(10, 250) pressdifiltro = randint(0, 30) presscomb = randint(300, 700) admbombcomb = randint(0, 200) presscremalheiracomb = randint(75000, 81000) tempcremalheiracomb = randint(15, 50) tempcomb = randint(25, 35) presscoletoradm2 = randint(-1, 100) tempcoletoradm2 = randint(25, 40) presscoletoradm1 = randint(0, 100) tempcoletadm = randint(25, 50) entrcmpturbo = randint(50, 100) presscombnfiltr = randint(700,800) #VIMS self.setPesoAcum.emit(str(pesoacum)) self.setDistPerCarr.emit(str(distpercarregado)) self.setTempViagem.emit(str(tempviagem)) self.setContTotalCarga.emit(str(contotalcarga)) self.setDerivPicoArm.emit(str(derivpicoarm)) self.setPassoPicoArm.emit(str(passopicoarm)) self.setInclPico.emit(str(inclpico)) self.setPressEsteioDE.emit(str(pressaoesteioDE)) self.setPressEsteioTE.emit(str(pressaoesteioTE)) self.setPressEsteioDD.emit(str(pressaoesteioDD)) self.setPressEsteioTD.emit(str(pressaoesteioTD)) self.setTempPercurso.emit(str(tempopercurso)) pesoacum = pesoacum + 1 distpercarregado = distpercarregado + 1 tempviagem = tempviagem + 1 contotalcarga = contotalcarga + 1 derivpicoarm = randint(500, 800) passopicoarm = randint(2000, 2500) inclpico = randint(-273, 100) pressaoesteioDE = randint(1500, 3000) pressaoesteioTE = randint(1500, 3000) pressaoesteioDD = randint(1500, 3000) pressaoesteioTD = randint(1500, 3000) tempopercurso = tempopercurso + 1 if __name__ == "__main__": app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() main = MainWindow() engine.rootContext().setContextProperty("backend", main) engine.load(os.fspath(Path(__file__).resolve().parent / "main.qml")) if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec_())
-
Please add the qml file as well.
Also, use coding tags when you post your code (the
</>
button in the toolbar). I fixed it in your last post. -
import QtQuick 2.0 Item { Rectangle { id: rectangle anchors.fill: parent color: "#d9d9d9" Rectangle { id: rectangle1 width: parent.width height: 62 color: "#000000" anchors.left: parent.left anchors.top: parent.top anchors.leftMargin: 0 anchors.topMargin: 0 Text { id: text1 color: "#ffffff" text: qsTr("Serviço: Parâmetros do Freio") anchors.left: parent.left anchors.top: parent.top anchors.bottom: parent.bottom font.pixelSize: 40 font.styleName: "Medium" anchors.leftMargin: 8 anchors.bottomMargin: 8 anchors.topMargin: 9 } } Grid { id: grid anchors.left: parent.left anchors.right: parent.right anchors.top: rectangle1.bottom anchors.bottom: parent.bottom flow: Grid.TopToBottom spacing: 20 rows: 2 columns: 2 anchors.bottomMargin: 38 anchors.rightMargin: 20 anchors.leftMargin: 22 anchors.topMargin: 59 Rectangle { x: 0 y: 300 id: rectangle2 width: 700 height: 350 color: "#d9d9d9" border.color: "#000000" border.width: 0.6 Text { id: text2 width: 359 height: 350 text: qsTr("Sol Embr Comp AC <br>Modo Auto Retardador <br>Filtro Arref Freio LD<br>Estado Filtro Freio<br>Temp Óleo Freio (ED)<br>Temp Óleo Freio (ET)") anchors.left: parent.left anchors.top: parent.top font.pixelSize: 31 lineHeight: 1.65 wrapMode: Text.Wrap font.styleName: "Medium" anchors.leftMargin: 8 anchors.topMargin: 8 minimumPixelSize: 12 } Text { id: solembr x: 523 y: 135 width: 62 height: 38 text: qsTr("Desl") anchors.left: parent.left anchors.top: parent.top font.pixelSize: 31 horizontalAlignment: Text.AlignHCenter font.styleName: "Medium" anchors.leftMargin: 614 anchors.topMargin: 8 Connections { target: backend function onSetSolEmbr(a) { solembr.text = a } } } Text { id: autoretard width: 75 height: 38 x:523 y:135 text: qsTr("Ativo") anchors.left: parent.left anchors.top: parent.top font.pixelSize: 31 horizontalAlignment: Text.AlignHCenter font.styleName: "Medium" anchors.leftMargin: 614 anchors.topMargin: 67 Connections { target: backend function onSetModoAutoRetard(b) { autoretard.text = b } } } Text { id: filtroarref x: 525 y: 127 width: 62 height: 38 text: qsTr("OK") anchors.left: parent.left anchors.top: parent.top font.pixelSize: 31 horizontalAlignment: Text.AlignHCenter font.styleName: "Medium" anchors.leftMargin: 614 anchors.topMargin: 122 Connections { target: backend function onSetFiltroArrefFreio(c) { filtroarref.text = c } } } Text { id: estadofiltro x: 522 y: 144 width: 183 height: 38 text: qsTr("Nao Desvian") anchors.left: parent.left anchors.top: parent.top font.pixelSize: 31 horizontalAlignment: Text.AlignHCenter font.styleName: "Medium" anchors.leftMargin: 506 anchors.topMargin: 181 Connections { target: backend function onSetEstadoFiltroFreio(d) { estadofiltro.text = d } } } Text { id: tempEDLabel x: 531 y: 135 width: 62 height: 38 text: qsTr("37") anchors.left: parent.left anchors.top: parent.top font.pixelSize: 31 horizontalAlignment: Text.AlignHCenter font.styleName: "Medium" anchors.leftMargin: 562 anchors.topMargin: 239 Connections { target: backend function onSetTempED(temp1) { tempEDLabel.text = temp1 } } } Text { id: tempETLabel x: 531 y: 144 width: 62 height: 38 text: qsTr("39") anchors.left: parent.left anchors.top: parent.top font.pixelSize: 31 horizontalAlignment: Text.AlignHCenter font.styleName: "Medium" anchors.leftMargin: 562 anchors.topMargin: 297 Connections { target: backend function onSetTempET(temp2) { tempETLabel.text = temp2 } } } Text { id: text4 x: 634 width: 58 height: 350 text: qsTr("<br><br><br><br>°C<br>°C") anchors.top: parent.top font.pixelSize: 31 lineHeight: 1.65 font.styleName: "Medium" anchors.topMargin: 8 anchors.leftMargin: 6 } } } Image { id: voltar x: 22 y: 498 width: 50 height: 50 source: "../../images/seta-para-tras.png" fillMode: Image.PreserveAspectFit MouseArea { id: mouseArea10 x: 0 y: 0 width: 50 height: 55 onClicked: source = "../../SortedbyECM.qml" } } Image { id: downbutton x: 295 y: 498 width: 50 height: 50 source: "../../images/seta-para-baixo.png" fillMode: Image.PreserveAspectFit MouseArea { id: mouseArea1 x: 0 y: 0 width: 50 height: 55 onClicked: source = "Brake_1.qml" } } }
Can I send you the full project via email? I can't show it complete here because copyrights.
-
One main issue with your code is that all your signals have in fact slot names.
You should rather have something like:
class Backend(QObject): modoAutoRetardChanged = Signal(str)
and in your QML:
Connections { target: backend function onModoAutoRetardChanged(b) { autoretard.text = b } }
That will make things clearer to understand and follow.
By the way, this is not a minimal runable example as requested. This QML file requires images that are not there and all the connections are done to signals that do not exists in your python code.