我刚在Ubuntu 22.04上安装了Qt6:
sudo apt-get install qt6-base-dev qt6-declarative-dev qt6-base-dev qtcreator
我已经打开了qtcreator
,并使用默认代码创建了一个新的Qt Quick Application
:
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
main.qml
import QtQuick 2.15 *QML module not found (QtQuick).*
import QtQuick.Window 2.15 *QML module not found (QtQuick.Window).*
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
}
以及以下编译错误:
09:14:30: Starting /home/myself/build-qttest-Desktop-Debug/qttest...
QML debugging is enabled. Only use this in a safe environment.
Warning: Ignoring WAYLAND_DISPLAY on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
QQmlApplicationEngine failed to load component
qrc:/main.qml:2:1: module "QtQuick.Window" is not installed
qrc:/main.qml:1:1: module "QtQuick" is not installed
qrc:/main.qml:2:1: module "QtQuick.Window" is not installed
qrc:/main.qml:1:1: module "QtQuick" is not installed
09:14:30: /home/myself/build-qttest-Desktop-Debug/qttest exited with code 255
以下是我的图书馆:
$ dpkg --get-selections | grep libqt
libqt5concurrent5:amd64 install
libqt5core5a:amd64 install
libqt5dbus5:amd64 install
libqt5designer5:amd64 install
libqt5designercomponents5:amd64 install
libqt5gui5:amd64 install
libqt5help5:amd64 install
libqt5network5:amd64 install
libqt5positioning5:amd64 install
libqt5printsupport5:amd64 install
libqt5qml5:amd64 install
libqt5qmlmodels5:amd64 install
libqt5qmlworkerscript5:amd64 install
libqt5quick5:amd64 install
libqt5quicktest5:amd64 install
libqt5quickwidgets5:amd64 install
libqt5sensors5:amd64 install
libqt5serialport5:amd64 install
libqt5sql5:amd64 install
libqt5sql5-sqlite:amd64 install
libqt5svg5:amd64 install
libqt5test5:amd64 install
libqt5webchannel5:amd64 install
libqt5webkit5:amd64 install
libqt5widgets5:amd64 install
libqt5xml5:amd64 install
libqt5xmlpatterns5:amd64 install
libqt6concurrent6:amd64 install
libqt6core6:amd64 install
libqt6dbus6:amd64 install
libqt6gui6:amd64 install
libqt6labsanimation6:amd64 install
libqt6labsfolderlistmodel6:amd64 install
libqt6labsqmlmodels6:amd64 install
libqt6labssettings6:amd64 install
libqt6labssharedimage6:amd64 install
libqt6labswavefrontmesh6:amd64 install
libqt6network6:amd64 install
libqt6opengl6:amd64 install
libqt6opengl6-dev:amd64 install
libqt6openglwidgets6:amd64 install
libqt6printsupport6:amd64 install
libqt6qml6:amd64 install
libqt6qmlcore6:amd64 install
libqt6qmllocalstorage6:amd64 install
libqt6qmlmodels6:amd64 install
libqt6qmlworkerscript6:amd64 install
libqt6qmlxmllistmodel6:amd64 install
libqt6quick6:amd64 install
libqt6quickcontrols2-6:amd64 install
libqt6quickcontrols2impl6:amd64 install
libqt6quickdialogs2-6:amd64 install
libqt6quickdialogs2quickimpl6:amd64 install
libqt6quickdialogs2utils6:amd64 install
libqt6quicklayouts6:amd64 install
libqt6quickparticles6:amd64 install
libqt6quickshapes6:amd64 install
libqt6quicktemplates2-6:amd64 install
libqt6quicktest6:amd64 install
libqt6quickwidgets6:amd64 install
libqt6sql6:amd64 install
libqt6sql6-sqlite:amd64 install
libqt6test6:amd64 install
libqt6widgets6:amd64 install
libqt6xml6:amd64 install
如何修复错误并编译它?
1条答案
按热度按时间zyfwsgd61#
试试这个
sudo apt install qml-module-qtquick2 qml-module-qtquick-window2