问题
I'm following this tutorial and I'm having a lot of QML module errors. I had to modify to QtQuick.Controls 1.1
because 2.0, 2.1, 2.3
wouldn't work. Here's my QML now:
import QtQuick.Window 2.1
import QtQuick 2.0
import QtQuick.Controls 1.1
import QtQuick.Controls.Material 2.1
Now I get only
"QtQuick.Controls.Material" is not installed
I'm using Ubuntu 17.10.1 and my PyQt
reports version 5.7
. Qt's website says:
Import Statement: import QtQuick.Controls.Material 2.3
Since: Qt 5.7
but it won't work. Since I have Qt 5.7
I should be able to use material design as the site says. But I can't even use QtQuick.Controls 2.x
.
I don't wanna install Qt 5.8 because then my app won't be compatible with older linuxes. I need to use 5.7.
How should I make this work?
UPDATE:
After trying on my machine and losing track of what I had installed I created a docker container to test it:
FROM ubuntu:latest
ARG SIP_LINK=https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.7/sip-4.19.7.tar.gz
ARG PYQT5_LINK=https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.10/PyQt5_gpl-5.10.tar.gz
RUN apt-get update \
&& apt-get install -y build-essential make wget ca-certificates \
python3 python3-dev \
qt5-default qml-module-qtquick-controls libqt5qml5 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
#SIP INSTALLAITON
RUN wget --progress=bar:force -O sip.tar.gz $SIP_LINK \
&& mkdir sip \
&& tar -xzvf sip.tar.gz -C sip --strip-components=1 \
&& rm sip.tar.gz \
&& cd sip \
&& python3 configure.py && make && make install \
&& cd .. \
&& rm -rf sip
#PYQT5 INSTALLAITON
RUN wget --progress=bar:force -O pyqt5.tar.gz $PYQT5_LINK \
&& mkdir pyqt5 \
&& tar -xzvf pyqt5.tar.gz -C pyqt5 --strip-components=1 \
&& rm pyqt5.tar.gz \
&& cd pyqt5 \
&& python3 configure.py --confirm-license && make && make install \
&& cd .. \
&& rm -rf pyqt5
WORKDIR /home/project
ENTRYPOINT "/bin/bash"
When I do
docker run --rm -it -v /tmp/.X11-unix:/tmp/.X11-unix -v /home/lz/project:/home/project -e DISPLAY=unix$DISPLAY test
and do ./main.py
(I'm following main.py from here, I get:
root@3054a751f04b:/home/prject# ./main.py
Traceback (most recent call last):
File "./main.py", line 4, in <module>
from PyQt5.QtQml import *
ImportError: No module named 'PyQt5.QtQml'
The packages qml-module-qtquick-controls libqt5qml5
were added just to try make it work but it didn't help
UPDATE 2:
After adding the package python3-pyqt5.qtquick
, I now get only the error:
QQmlApplicationEngine failed to load component
file:///home/project/main.qml:4 module "QtQuick.Controls.Material" is not installed
process 12: D-Bus library appears to be incorrectly set up; failed to read machine uuid: UUID file '/etc/machine-id' should contain a hex string of length 32, not length 0, with no other text
See the manual page for dbus-uuidgen to correct this issue.
However, I shouldn't have to add python3 qt packages because I'm building them
回答1:
The correct Ubuntu package for Qt Quick Controls 2 is qml-module-qtquick-controls2. This package includes the Material style.
回答2:
According to the Qt Documentation for QtQuick.Controls
versions, you should probably import QtQuick 2.7
instead of 2.0
when using Qt 5.7
:
import QtQuick 2.7
import QtQuick.Window 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
来源:https://stackoverflow.com/questions/48944407/trouble-using-qml-material-design-qtquick-controls-material-is-not-installed