PySide6 QtWebengine Throwing ERROR:Attempt to read from an uninitialized SharedImage
Solved
QtWebEngine
-
I am currently working on a desktop client with PySide6 in which I have to dynamically add new elements into the dom based on the data fetched from the server. I am using HTML/JS/CSS for this, but for some reason, it sometimes shows some white-colored squares on the screen and the console throws this:
[161300:224960:0417/084410.402:ERROR:shared_image_representation.cc(214)] Attempt to read from an uninitialized SharedImage [161300:224960:0417/084410.807:ERROR:shared_image_representation.cc(214)] Attempt to read from an uninitialized SharedImage [161300:224960:0417/084410.820:ERROR:shared_image_representation.cc(214)] Attempt to read from an uninitialized SharedImage
My Python Code:
import sys,os,requests from localStoragePy import localStoragePy from PySide6.QtWidgets import QApplication, QMainWindow from PySide6.QtCore import QUrl, Slot, QObject, QProcess from PySide6.QtGui import QIcon, QPixmap from PySide6.QtWebEngineWidgets import QWebEngineView from PySide6.QtWebEngineCore import QWebEngineSettings from PySide6.QtWebChannel import QWebChannel import renderer app = QApplication(sys.argv) os.environ['QTWEBENGINE_REMOTE_DEBUGGING'] = "9000" try: from ctypes import windll myappid = 'prayag17.jellyplayer.0.1.0' windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) except ImportError: pass storage = localStoragePy('prayag.jellyplayer.app', 'sqlite') def restart(): QApplication.quit() status = QProcess.startDetached(sys.executable, sys.argv) class Backend(QObject): @Slot(result=str) def onStartup(self): if storage.getItem("serverGo") == "True": try: ping = requests.get(f"{storage.getItem('server')}/System/Ping") if ping.content == b'"Jellyfin Server"': if storage.getItem("openHome") == "True": return "openHomeTrue" else: return "serverGoTrue" except: return "serverOffline" else: return "serverGoFalse" @Slot(result=list) def getAuthinfo(self): return [storage.getItem("UserName"), storage.getItem("UserPw")] @Slot(str, result=bool) def saveServer(self, data): ping = requests.get(f"{data}/System/Ping") if ping.content == b'"Jellyfin Server"': storage.setItem('server', data) storage.setItem("serverGo", True) return True else: storage.setItem("serverGo", False) return False @Slot(str, result=bool) def getValuesFromDatabaseBool(self, object): print(f"Object: {object}") item = storage.getItem(object) print(item) if item == "True": return True elif item == "False": return False @Slot(str, result=str) def getValuesFromDatabaseStr(self, object): print(f"Object: {object}") item = storage.getItem(object) print(item) return item @Slot(str, str) def setAuthInfoDatabase(self, userName, Pw): print(f"User: {userName}, Password: {Pw}") storage.setItem("UserName", userName) storage.setItem("UserPw", Pw) storage.setItem("openHome", True) @Slot() def clearStorage(self): storage.clear() restart() @Slot() def restart(self): QApplication.quit() status = QProcess.startDetached(sys.executable, sys.argv) class LoginWin(QMainWindow): def __init__(self): super().__init__() self.dir = os.path.dirname(os.path.abspath(__file__)) self.view= QWebEngineView(self) self.setCentralWidget(self.view) # self.setWindowIcon() self.view.settings().setAttribute(QWebEngineSettings.JavascriptEnabled, True) self.view.settings().setAttribute(QWebEngineSettings.PluginsEnabled, True) self.view.settings().setAttribute(QWebEngineSettings.LocalContentCanAccessRemoteUrls, True) self.view.settings().setAttribute(QWebEngineSettings.ScrollAnimatorEnabled, True) self.setWindowTitle('JellyPlayer') self.setWindowIcon(QIcon(QPixmap(":/assets/icon.png"))) self.view.load(QUrl("qrc:/renderer/html/main.html")) self.view.loadFinished.connect(self.handleLoaded) self.inspector = QWebEngineView() self.inspector.setWindowTitle("Inspector") self.inspector.load(QUrl("http://127.0.0.1:9000")) self.backend = Backend() self.channel = QWebChannel() self.channel.registerObject('backend', self.backend) self.view.page().setWebChannel(self.channel) def handleLoaded(self, ok): if ok: self.view.page().setDevToolsPage(self.inspector.page()) self.inspector.show() window = LoginWin() window.showMaximized() sys.exit(app.exec())
Here renderer is just compiled qrc code
JS code:
const createUserList = async (server) => { document.querySelector('.loader').classList.remove('hide'); let users = await window.userApi.getPublicUsers(); let userlist = users.data; console.log(userlist); if (userlist.length != 0) { userlist.forEach(user => { if (user.PrimaryImageTag) { html = `<div class="user__card" data-user="${user.Name}" data-userid="${user.Id}" onclick="createEnterPassword(this.dataset.user, true, this.dataset.userid)"> <div class="content"> <img class="user__img" src="${server}/Users/${user.Id}/Images/Primary"> <h1>${user.Name}</h1> </div> </div>`; } else if (!user.PrimaryImageTag) { html = `<div class="user__card" data-user="${user.Name}" onclick="createEnterPassword(this.dataset.user, false)"> <div class="content"> <img class="user__svg" src="../svg/avatar.svg"> <h1>${user.Name}</h1> </div> </div>`; } document.querySelector('.user__cont').insertAdjacentHTML('beforeend', html); }); document.querySelector('.users').classList.remove('hide'); document.querySelector(".purple").classList.add("active"); document.querySelector('.users').scrollIntoView({ behavior: "smooth" }); document.querySelector('.loader').classList.add('hide'); setTimeout(() => { document.querySelector('.server').classList.add('hide'); }, 1000); }else if (userlist.length == 0) { document.querySelector('.loader').classList.add('hide'); createManualLogin(false); setTimeout(() => { document.querySelector('.server').classList.add('hide'); }, 1000); } };
I have just attached snippet of the js code as it is quite big but if you want to see the full code go to https://github.com/prayag17/JellyPlayer
Qt Version: 6.3.0
Python version: 3.10.X