Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. QT: Updates can only be scheduled from GUI thread or from QQuickItem::updatePaintNode()

QT: Updates can only be scheduled from GUI thread or from QQuickItem::updatePaintNode()

Scheduled Pinned Locked Moved Unsolved India
1 Posts 1 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Myself.Shivu
    wrote on 10 Jan 2020, 12:17 last edited by
    #1

    I'm trying to change Image with Pushbutton (GPIO PINs) stored inside a folder using QML with PyQt5

    Python Code:

    from gpiozero import Button
    from signal import pause
    
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtQml import *
    import os, time, sys
    
    
    def btn_pressed():
        global r
        return lambda: r.setProperty("source", "/home/pi/Desktop/example/sample/img/img1.jpg")
    
    button1 = Button(20)        
    myApp = QGuiApplication([])
    myEngine = QQmlApplicationEngine()
    directory = os.path.dirname(os.path.abspath(__file__))
    myEngine.load(QUrl.fromLocalFile(os.path.join(directory, 'simple1.qml')))
    if not myEngine.rootObjects():
        print("root object not found")
    
    r = myEngine.rootObjects()[0].findChild(QObject, "DisplayImage")
    dir(r)
    print("Main Thead id ",myApp.thread())
    updateUI = UpdateUI()
    
    button1.when_pressed = btn_pressed()   
    myEngine.quit.connect(myApp.quit)
    sys.exit(myApp.exec_())
    

    QML:

    import QtQuick 2.10
    import QtQuick.Controls 1.6
    import QtQuick.Window 2.2
    
    ApplicationWindow {
        id : main
        title: qsTr("Test")
        width: 640
        height: 480
        visible: true
    
        Rectangle{
            width: parent.width
            height: parent.height
    
            Image {
                id: img
                source: ""
                width : main.width;
                fillMode : Image.PreserveAspectFit
                objectName: "DisplayImage"
            }
        }
    }
    
    When I Pressed the Push Button Connected to GPIO 20 in raspberry Pi 4 , I'm Getting below error message
    
    
    
    list itemQObject: Cannot create children for a parent that is in a different thread
    (Parent is QQmlApplicationEngine(0x10f5ba0),
    parents thread is QThread(0xf6f7c0)
    current thread is QThread(0xa98007c8)
    Updates can only be scheduled from GUI thread or from QQuickItem::updatePaintNode()
    
    
    I also tried creating class with a method changing Image Source Property and then calling the same method(via Class Object) upon PushButton press but it shows same error message
    
    Is there a way to set Image Source Property in QML - from parent thread in Python.
    In Winforms we can Avoid "Cross-Thread Violation Error" by using Delegates.
    Can we Use `Signal and Slot` to Solve this Problem in PyQt5
    1 Reply Last reply
    0

    1/1

    10 Jan 2020, 12:17

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved