If you want to know the error message when using QQmlApplicationEngine you should use the warnings
signal but it does not seem to work, so a workaround is to use qInstallMessageHandler
to get the messages that Qt gives.
import os
import sys
from PySide2
import QtCore, QtGui, QtQml
def qt_message_handler(mode, context, message):
if mode == QtCore.QtInfoMsg:
mode = 'Info'
elif mode == QtCore.QtWarningMsg:
mode = 'Warning'
elif mode == QtCore.QtCriticalMsg:
mode = 'critical'
elif mode == QtCore.QtFatalMsg:
mode = 'fatal'
else:
mode = 'Debug'
print("%s: %s (%s:%d, %s)" % (mode, message, context.file, context.line, context.file))
if __name__ == '__main__':
os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"
QtCore.qInstallMessageHandler(qt_message_handler)
app = QtGui.QGuiApplication(sys.argv)
engine = QtQml.QQmlApplicationEngine()
qml_filename = os.path.join(os.path.dirname(__file__), 'QML/main.qml')
engine.load(QtCore.QUrl.fromLocalFile(qml_filename))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
I have the following code:,As you can see, if `engine.load' fails all anycodings_pyside2 I'll see is a '-1' exit code, without any anycodings_pyside2 elaboration on why it failed and what the anycodings_pyside2 error happened. How can I print the QML anycodings_pyside2 error in the python console?,Global array works in function with alert/console.log, but not when indexed with variable,Most efficient way to merge sorted collections into a new sorted collection?
I have the following code:
if __name__ == '__main__':
os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load('./QML/main.qml')
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
If you want to know the error message anycodings_pyside2 when using QQmlApplicationEngine you anycodings_pyside2 should use the warnings signal but it anycodings_pyside2 does not seem to work, so a workaround anycodings_pyside2 is to use qInstallMessageHandler to get anycodings_pyside2 the messages that Qt gives.
import os
import sys
from PySide2
import QtCore, QtGui, QtQml
def qt_message_handler(mode, context, message):
if mode == QtCore.QtInfoMsg:
mode = 'Info'
elif mode == QtCore.QtWarningMsg:
mode = 'Warning'
elif mode == QtCore.QtCriticalMsg:
mode = 'critical'
elif mode == QtCore.QtFatalMsg:
mode = 'fatal'
else:
mode = 'Debug'
print("%s: %s (%s:%d, %s)" % (mode, message, context.file, context.line, context.file))
if __name__ == '__main__':
os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"
QtCore.qInstallMessageHandler(qt_message_handler)
app = QtGui.QGuiApplication(sys.argv)
engine = QtQml.QQmlApplicationEngine()
qml_filename = os.path.join(os.path.dirname(__file__), 'QML/main.qml')
engine.load(QtCore.QUrl.fromLocalFile(qml_filename))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
If you want to know the error message when using QQmlApplicationEngine you should use the warnings signal but it does not seem to work, so a workaround is to use qInstallMessageHandler to get the messages that Qt gives.
If you want to know the error message when using QQmlApplicationEngine you should use the warnings
signal but it does not seem to work, so a workaround is to use qInstallMessageHandler
to get the messages that Qt gives.
import os
import sys
from PySide2
import QtCore, QtGui, QtQml
def qt_message_handler(mode, context, message):
if mode == QtCore.QtInfoMsg:
mode = 'Info'
elif mode == QtCore.QtWarningMsg:
mode = 'Warning'
elif mode == QtCore.QtCriticalMsg:
mode = 'critical'
elif mode == QtCore.QtFatalMsg:
mode = 'fatal'
else:
mode = 'Debug'
print("%s: %s (%s:%d, %s)" % (mode, message, context.file, context.line, context.file))
if __name__ == '__main__':
os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"
QtCore.qInstallMessageHandler(qt_message_handler)
app = QtGui.QGuiApplication(sys.argv)
engine = QtQml.QQmlApplicationEngine()
qml_filename = os.path.join(os.path.dirname(__file__), 'QML/main.qml')
engine.load(QtCore.QUrl.fromLocalFile(qml_filename))
if not engine.rootObjects():
sys.exit(-1)
sys.exit(app.exec_())
Copy
The Qt QML module provides services for debugging, inspecting, and profiling applications via a TCP port or a local socket.,QML Debugger: Waiting for connection on port <port_number> or QML Debugger: Connecting to socket at <file>",To enable debugging -- from the start or to attach a debugger later on -- start the application with the following arguments:,Alternatively, a logging category can be passed as the first argument to any of these console functions. See LoggingCategory for more details.
For example:
function f(a, b) {
console.log("a is ", a, "b is ", b);
}
For example:
function f() {
var x = 12
console.assert(x == 12, "This will pass");
console.assert(x > 12, "This will fail");
}
For example:
function f() {
console.time("wholeFunction");
console.time("firstPart");
// first part
console.timeEnd("firstPart");
// second part
console.timeEnd("wholeFunction");
}
For example:
function f() {
console.count("f called");
}
For example:
function f() {
console.profile();
//Call some function that needs to be profiled.
//Ensure that a client is attached before ending
//the profiling session.
console.profileEnd();
}
import QtQuick
Rectangle {
width: 100;height: 100
}
This wiki explains how to build your own user interface using Qt for Python on the reTerminal. Here we have used PySide2 for the development. PySide2 is the official Python module from the Qt for Python project, which provides access to the complete Qt5 framework.Qt for Python allows you to build interactive user interfaces in a more user friendly way! It is also very flexible to use and has a short learning curve. ,If you want to experience a more interesting demo with Qt for Python, you can checkout this GitHub repo,Note: Later we will use Visual Studio Code to create files inside the reTerminal and build our project,Note: We have to install QtQuick.Studio manually because default Debian and Ubuntu OS don't have this module
sudo apt install qml - module - qtquick - shapes python3 - pyside2.qtqml python3 - pyside2.qtcore python3 - pyside2.qtnetwork python3 - pyside2.qtgui python3 - pyside2.qtwidgets python3 - pyside2.qtquick qtquickcontrols2 - 5 - dev qml - module - qtcharts qml - module - qtquick - controls qml - module - qtquick - controls2
sudo apt install qmake qt5 - defaults
git clone git: //github.com/Pillar1989/qtquickdesigner-components.git
cd qtquickdesigner - components
qmake
make
sudo make install
pi @192.xxx.xx.xx
// import library
import QtQuick.Controls 2.1
// properties of the application window containing UI elements
ApplicationWindow {
id: application
width: 1280
height: 720
visible: true
visibility: "FullScreen"
// initialize the first window of the application
property
var iniITEM: "LedGui.qml"
// stack-based navigation model
StackView {
id: stackview
initialItem: iniITEM
}
}