QML.jl: No applicable_loaders found for QML - qt

I am unable to use QML.jl as my code fails with the following error
ERROR: No applicable_loaders found for QML
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] applicable_loaders at /home/wali/.julia/packages/FileIO/BUPwf/src/loadsave.jl:11 [inlined]
[3] load(::String; options::Base.Iterators.Pairs{Symbol,String,Tuple{Symbol},NamedTuple{(:greeting,),Tuple{String}}}) at /home/wali/.julia/packages/FileIO/BUPwf/src/loadsave.jl:112
[4] #3 at ./REPL[18]:17 [inlined]
[5] mktempdir(::var"#3#4", ::String; prefix::String) at ./file.jl:709
[6] mktempdir(::Function, ::String) at ./file.jl:707 (repeats 2 times)
[7] top-level scope at REPL[18]:1
The tests for the package also fail with the same error.
Here is the code I am trying to run if that helps
mktempdir() do folder
path = joinpath(folder, "main.qml")
write(path, """
import QtQuick 2.0
import QtQuick.Controls 1.0
ApplicationWindow {
visible: true
Text {
text: greeting
}
Timer {
running: true
onTriggered: Qt.quit()
}
}
""")
load(path; greeting = "Hello, World!")
exec()
end

I had the same problem. If you use the following code snippets and especially use loadqml() instead of load()
The folder structure looks like this:
src/
hello.jl
qml/
hello.qml
So I created a separated hello.qml file like this in a qml subfolder:
import QtQuick 2.6
import QtQuick.Controls 2.3
ApplicationWindow {
visible: true
Text {
text: greeting
}
Timer {
running: true
onTriggered: Qt.quit()
}
}
The Julia code looks like this in hello.jl:
using QML
using Qt5QuickControls2_jll
qml_file = joinpath(dirname(#__FILE__), "qml", "hello.qml")
loadqml(
qml_file,
greeting = "Hello, World!"
)
# Start the GUI
exec()
If you run from src folder julia hello.jl this should return
I used Julia version Version 1.6.3 and installed the following packages:
Pkg.add("IJulia")
Pkg.add("QML")
Pkg.add("Observables")
Pkg.add("Qt5QuickControls2_jll")
Pkg.add("Qt5QuickControls_jll")

Related

Qt6 with Cmake submodule ReferenceError

I have a QT6 Qml with a Cmake File like this
cmake_minimum_required(VERSION 3.16)
project(appTEST VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.2 COMPONENTS Gui Qml Quick REQUIRED)
set(CPPSOURCES
...)
set(CPPHEADERS
...)
qt_add_executable(appTEST
main.cpp
${CPPSOURCES}
${CPPHEADERS}
)
target_link_libraries(appTEST
PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Quick
Qt6::Qml)
install(TARGETS appTEST
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
qt6_add_qml_module(appTEST
URI "Main"
VERSION 1.0
NO_PLUGIN
QML_FILES main.qml
)
add_subdirectory(content)
add_subdirectory(imports)
target_link_libraries(appTEST PRIVATE
contentplugin
impplugin
)
and the content module:
qt_add_library(content STATIC)
qt6_add_qml_module(content
URI "content"
VERSION 1.0
QML_FILES
...
)
and imp module :
set_source_files_properties(Constants.qml
PROPERTIES
QT_QML_SINGLETON_TYPE true
)
...
qt_add_library(imp STATIC)
qt6_add_qml_module(imp
URI "imp"
VERSION 1.0
QML_FILES
Constants.qml
...
)
with the constatnt.qml marked as a Singleton like this:
pragma Singleton
import QtQuick 6.3
QtObject {
...
}
so I expect to be able to import imp on any page and have access to constatnt.qml properties.
but in run time get this error
ReferenceError: Constants is not defined
note tath I tried to adopt the structure from Qt Design Studio default project template.

Import Error after installing pyotherside

I tried installing pyotherside from the ubuntu repos (packages qml-module-io-thp-pyotherside and pyotherside) as well as from the git repo.
But in when importing it in Python3 I keep getting ImportError: No module named 'pyotherside'.
Any knows why? What is the path where I should find pyotherside installed?
OS: Ubuntu 16.04.2
PyOtherSide is a library that uses the python code from QML and not vice versa, in your project you must the qml file and the python file. To run the program you must execute the qml, for example:
{your directory}
├── imageprovider.py
└── imageprovider.qml
imageprovider.py
import pyotherside
import math
def render(image_id, requested_size):
print('image_id: "{image_id}", size: {requested_size}'.format(**locals()))
# width and height will be -1 if not set in QML
if requested_size == (-1, -1):
requested_size = (300, 300)
width, height = requested_size
# center for circle
cx, cy = width/2, 10
pixels = []
for y in range(height):
for x in range(width):
pixels.extend(reversed([
255, # alpha
int(10 + 10 * ((x - y * 0.5) % 20)), # red
20 + 10 * (y % 20), # green
int(255 * abs(math.sin(0.3*math.sqrt((cx-x)**2 + (cy-y)**2)))) # blue
]))
return bytearray(pixels), (width, height), pyotherside.format_argb32
pyotherside.set_image_provider(render)
imageprovider.qml
import QtQuick 2.0
import io.thp.pyotherside 1.5
Image {
id: image
width: 300
height: 300
Python {
Component.onCompleted: {
// Add the directory of this .qml file to the search path
addImportPath(Qt.resolvedUrl('.'));
importModule('imageprovider', function () {
image.source = 'image://python/image-id-passed-from-qml';
});
}
onError: console.log('Python error: ' + traceback)
}
}
You open a terminal run:
qmlscene {your directory}/imageprovider.qml

PyQt4: How to load compiled ui-files correctly?

I created a Qt resource file with all my ui files inside of it, I compiled that with pyrcc4 command-line in a python file, and then I loaded the ui files using loadUi. Here an example:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
import sys
from PyQt4.QtCore import Qt, QFile
from PyQt4.uic import loadUi
from PyQt4.QtGui import QDialog
from xarphus.gui import ui_rc
# I import the compiled qt resource file named ui_rc
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
#UI_PATH = os.path.join(BASE_PATH, 'gui', 'create_user.ui')
UI_PATH = QFile(":/ui_file/create_user.ui")
# I want to load those compiled ui files,
# so I just create QFile.
class CreateUser_Window(QDialog):
def __init__(self, parent):
QDialog.__init__(self, parent)
# I open the created QFile
UI_PATH.open(QFile.ReadOnly)
# I read the QFile and load the ui file
self.ui_create_user = loadUi(UI_PATH, self)
# After then I close it
UI_PATH.close()
Well its works fine, but I have a problem. When I open the GUI-window once, everything works fine. After closing the window I try to open the same GUI-window again, I get ja long traceback.
Traceback (most recent call last): File "D:\Dan\Python\xarphus\xarphus\frm_mdi.py", line 359, in
create_update_form self.update_form = Update_Window(self) File
"D:\Dan\Python\xarphus\xarphus\frm_update.py", line 135, in init
self.ui_update = loadUi(UI_PATH, self) File
"C:\Python27\lib\site-packages\PyQt4\uic__init__.py", line 238, in
loadUi return DynamicUILoader(package).loadUi(uifile, baseinstance,
resource_suffix) File
"C:\Python27\lib\site-packages\PyQt4\uic\Loader\loader.py", line 71,
in loadUi return self.parse(filename, resource_suffix, basedir) File
"C:\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 984, in
parse document = parse(filename) File
"C:\Python27\lib\xml\etree\ElementTree.py", line 1182, in parse
tree.parse(source, parser) File
"C:\Python27\lib\xml\etree\ElementTree.py", line 657, in parse
self._root = parser.close() File
"C:\Python27\lib\xml\etree\ElementTree.py", line 1654, in close
self._raiseerror(v) File "C:\Python27\lib\xml\etree\ElementTree.py",
line 1506, in _raiseerror raise err xml.etree.ElementTree.ParseError:
no element found: line 1, column 0
Can everyone help me?
Maybe I have a solution, but I don't know if that is a perfectly pythonic.
Well, we know all python projects have an __ init __-file. We need it for initializing Python packages, right? Well I thought: Why not use this file? What did I do? I define in the __ init __ -file a function like so:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from PyQt4.uic import loadUi
from PyQt4.QtCore import Qt, QFile
def ui_load_about(self):
uiFile = QFile(":/ui_file/about.ui")
uiFile.open(QFile.ReadOnly)
self.ui_about = loadUi(uiFile)
uiFile.close()
return self.ui_about
Now in my "About_Window"-class I do this:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
import sys
from PyQt4.QtCore import Qt, QFile
from PyQt4.uic import loadUi
from PyQt4.QtGui import QDialog
import __init__ as ui_file
class About_Window(QDialog):
def __init__(self, parent):
QDialog.__init__(self, parent)
self.ui_about = ui_file.ui_load_about(self)
You see I importe the package-file (__ init __-file) as ui_file and then I call the function and save the return of the function in the variable self.ui_about.
In my case I open the About_Window from a MainWindow(QMainWindow), and it looks like so:
def create_about_form(self):
self.ui_about = About_Window(self)
# Now when I try to show (show()-method) a window I get two windows
# The reason is: I open and load the ui files from compiled
# qt resorce file that was define in __init__-module.
# There is a function that opens the resource file, reads
# the ui file an closes and returns the ui file back
# That's the reason why I have commented out this method
#self.ui_about.show()
You see I commented out the show()-method. It works without this method. I only define the About_Window()-class. Well I know that isn't maybe the best solution, but it works. I can open the window again and again without traceback.
If you have a better solution or idea let me know :-)

How to close Pyqt5 program from QML?

I started a project in Qt Creator initially with a C++ backend, but then switched it to use PyQt5. I have a main.qml, where when I press a button called Exit, I call Qt.quit().
However, I get a General Message stating: Signal QQmlEngine::quit() emitted, but no receivers connected to handle it.
My question is, how do I receive this signal and handle it?
Code:
main.py:
import sys
import PyQt5
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtQml
from PyQt5.QtCore import QObject pyqtSignal
class DestinyManager,(QtGui.QGuiApplication):
"""the app self"""
def __init__(self, argv):
super(DestinyManager, self).__init__(argv)
# Define a new signal called 'trigger' that has no arguments.
trigger = pyqtSignal()
def connect_and_emit_trigger(self):
# Connect the trigger signal to a slot.
self.trigger.connect(self.handle_trigger)
self.menuItem_Exit.clicked.connect(self.close)
# Emit the signal.
self.trigger.emit()
def handle_trigger(self):
# Show that the slot has been called.
print("trigger signal received")
def main(argv):
app = DestinyManager(sys.argv)
engine = QtQml.QQmlEngine(app)
component = QtQml.QQmlComponent(engine)
component.loadUrl(QtCore.QUrl("exit.qml"))
topLevel = component.create()
if topLevel is not None:
topLevel.show()
else:
for err in component.errors():
print(err.toString())
app.exec()
if __name__ == '__main__':
QObject,main(sys.argv)
Exit.qml:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
Window {
Button {
id: btn_Exit
text: "Exit"
onClicked: Qt.quit();
}
}
There are a few syntax errors in the python script, but ignoring those, the code can be made to work like this:
def main(argv):
app = DestinyManager(sys.argv)
engine = QtQml.QQmlEngine(app)
engine.quit.connect(app.quit)
...
Which is to say, you simply need to connect the qml quit signal to an appropriate slot in your python script.

QML FileDialog nameFilters case sensitive on Linux?

The following code will correctly display *.ext and *.EXT files on Windows and Mac. It does NOT display *.EXT (and of course *.Ext, *.eXt, *.exT...) files on Linux. What's my mistake?
import QtQuick 2.3
import QtQuick.Dialogs 1.1
FileDialog
{
title: "Please choose a file"
nameFilters: [ "Scene files (*.ext)" ]
selectMultiple: true
}
The Linux file system is case sensitive, and that is why it won't return *.EXT files.
The following should work:
nameFilters: [ "Scene files (*.ext *.EXT)" ]

Resources