PySide6 comes with segmentation fault on Mac - python

I am using Python 3.8.6 and PySide 6.0.1 and get a segmentation fault running the below sample.
When I comment the Text {} element the sample runs.
import sys
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine("view.qml")
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
import QtQuick 2.0
import QtQuick.Controls 2.5
ApplicationWindow
{
width: 640
height: 480
visible: true
title: "QML Demo"
Text
{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
text: "Hello World"
}
}

I can't test your code on Mac but as a suggestion you can remove all version numbers from imports in QML.
This is the only difference I can see here between PyQt5 and PyQt6.
(however your code works on Ubuntu 20.04)

Related

PySide6 QQmlApplicationEngine failed to load component

Hello I designed an my UI using Qt Design Studio (Community Edition) and exported it to a qrc file then compiled to Python using pyside6-rcc then loaded the main.qml file inside main.py using "qrc:/main.qml" resource link but I have these errors Type App not available.
This is my file structure;
- qml
- contents
* App.qml
* ... // Other Files
+ imports
* main.qml
* uifiles.qrc
* uifiles.py // Generated by [pyside6-rcc uifiles.qrc -o uifiles.py]
* main.py
Content of qml/content/App.qml;
import QtQuick
import QtQuick.Window
import "qrc:/content"
import QtQuick.VirtualKeyboard
Window {
width: mainScreen.width
height: mainScreen.height
visible: true
title: "IntelUI"
Screen01 {
id: mainScreen
}
InputPanel {
id: inputPanel
property bool showKeyboard : active
y: showKeyboard ? parent.height - height : parent.height
Behavior on y {
NumberAnimation {
duration: 200
easing.type: Easing.InOutQuad
}
}
anchors.leftMargin: Constants.width/10
anchors.rightMargin: Constants.width/10
anchors.left: parent.left
anchors.right: parent.right
}
}
Content of qml/main.qml;
import QtQuick
import "qrc:/content"
App {
}
Content of main.py;
import sys
import qml.uifiles
from PySide6.QtCore import QUrl
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(QUrl("qrc:/main.qml"))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec())
Errors generated by python main.py;
QQmlApplicationEngine failed to load component
qrc:/main.qml:7:1: Type App unavailable
qrc:/content/App.qml:42:5: Type Screen01 unavailable
qrc:/content/Screen01.ui.qml:41:13: Type MainStream unavailable
qrc:/content/MainStream.ui.qml:12:1: module "QtQuick.Studio.Components" is not installed
Note: I have the following installed PySide6, PySide6-Addons
Any help will useful. Thank You!

Failed to build graphics pipeline state in qt quick application

I have a qt quick pyside application .I had a question before,but now another proplem is there .Just a empty window appears and then in application window I see below message.Although I have another qt quick application that I written that in c++ and there is no problem displaying it, this message is displayed!,This application is in python(pyside6)
I use Qt 6.0.2,Python 3.9.2,Qt Creator 4.14.1 and Pyside6
Failed to create vertex shader: Error 0x80070057: The parameter is incorrect.
Failed to build graphics pipeline state
*main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
Window {
id:mainWindow
width: 1000
height: 580
visible: true
title: qsTr("JooyaTrader")
Rectangle{
width: 152
height: 62
anchors.fill: parent
color: "red"
}
}
main.py
import sys,os
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
import PySide6
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
The problem is caused because the backend that Qt Quick uses for rendering does not work for your case, either because there are missing libraries or the version is not according to what Qt expects. In that one solution is to set the QT_QUICK_BACKEND in "software" making the rendering do it Qt Quick 2D Renderer:
os.environ["QT_QUICK_BACKEND"] = "software"
app = QGuiApplication(sys.argv)
For more information read Scene Graph Adaptations.

Using QtCharts in Qt Creator with python

I am using Qt Creator to create a QtQuick program using Python. I want to add the QtCharts module to my QML files, but I get the error message
QML module not found (QtCharts)
In a QtQuick project using C++, one would include QtCharts by adding QT += charts in the .pro file.
Is there a similar command to add in the main.pyproj file?
Note that the program runs correctly when built through the python script, but I want to access the features used by the designer in Qt Creator.
The main.pyproject is as follows:
{"files": ["main.py","frontend/main.qml"]}
The main.py file:
import os
import sys
import PyQt5.QtQml
import PyQt5.QtCore
import PyQt5.QtWidgets
if __name__ == '__main__':
os.environ['QT_QUICK_CONTROLS_STYLE'] = 'Default'
app = PyQt5.QtWidgets.QApplication(sys.argv)
engine = PyQt5.QtQml.QQmlApplicationEngine()
engine.load('frontend/main.qml')
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
the frontend/main.qml file:
import QtQuick 2.12
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.12
import QtCharts 2.10
ApplicationWindow {
id: window
visible: true
title: 'Neuron Network Sandbox'
ChartView {
width: 400
height: 300
antialiasing: true
PieSeries {
id: pieSeries
PieSlice { label: "eaten"; value: 94.9 }
PieSlice { label: "not yet eaten"; value: 5.1 }
}
}
}

PyQt5 and QML integration issue with "findChild" returning AttributeError

I'm pretty new to PyQt5 and QML integration. I've been searching a long time about that problem and I can't find a scenario close enough to my case.
The error I'm having is the following(I'm using PyCharm):
File "D:/PyCharmProjects/SimpleQML.py", line 13, in __init__
self.win = self.root.findChild(QObject, "mainWindow")AttributeError: 'NoneType' object has no attribute 'findChild'
Here is my python code:
import sys
from PyQt5.QtCore import QUrl, QObject
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQuick import QQuickView
class SimpleQML(QQuickView):
def __init__(self, parent=None):
super(SimpleQML, self).__init__(parent)
self.setSource(QUrl.fromLocalFile("D:/Qt/SimpleQML/SimpleQML.qml"))
self.root = self.rootObject()
self.win = self.root.findChild(QObject, "mainWindow")
if __name__ == '__main__':
app = QApplication(sys.argv)
win = SimpleQML()
win.setTitle("SimpleQML")
win.setResizeMode(QQuickView.SizeRootObjectToView)
win.show()
sys.exit(app.exec_())
Here is my (really simple) QML code:
import QtQuick 2.6
import QtQuick.Window 2.2
Rectangle{
id: mainWindow
objectName: "mainWindow"
visible: true
width: 400
height: 400
color: "#323232"
}
And if you have any advice concerning the integration of QML with PyQt5 it's more than welcome.
Thank you in advance!
The error you get is valid since when you use the rootObject function you get the mainWindow rectangle, and when you do the search for your children you can not find any since you do not have children. To check it you can use:
print(self.root.objectName())
Output:
mainWindow
If you change the qml to:
import QtQuick 2.6
import QtQuick.Window 2.2
Item{
Rectangle{
id: mainWindow
objectName: "mainWindow"
visible: true
width: 400
height: 400
color: "#323232"
}
}
Then you get the mainWindow child.

Utilizing QtQuick Controls from PyQt5

First of all, I tried to use QtQuick from PySide. The latest PySide as of today wraps Qt 4.8, which doesn't have an actively developed desktop components. (colibri is there, but that's not for desktop, and it's buggy).
PyQt seems to win here, since the latest version (5.2.1 as of today), wraps Qt 5, which has QtQuick controls ready.
I've looked at many of the examples under Lib/site-packages/PyQt5/examples/quick, all of them work, but none of them use QtQuick Controls.
I am trying a very simple qml here:
//main.qml
import QtQuick.Controls 1.2
ApplicationWindow {
title: "My Application"
Button {
text: "Push Me"
anchors.centerIn: parent
}
}
and a python file:
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
import sys
if __name__ == "__main__":
app = QApplication(sys.argv)
engine = QQmlApplicationEngine("main.qml")
engine.quit.connect(app.quit)
sys.exit(app.exec_())
but i'm having this error:
.../main.qml:1 module "QtQuick.Controls" version 1.2 is not installed
Can I use QtQuick Controls from PyQt5?. And if so, how?. I can't find it anywhere.
Did you try to use QtQuick.Controls 1.0, it works fine on my system

Categories