我有以下目录结构:
ui/
|- resources.qrc
|- qml/
|- main_window_presenter.qml
|- MyPresenter.qml
resources.qrc 内容:
<RCC>
<qresource prefix="/">
<file>qml/MyPresenter.qml</file>
<file>qml/main_window_presenter.qml</file>
</qresource>
</RCC>
MyPresenter.qml 内容:
import QtQuick 2.11
FocusScope {
id: root
property Item view
property QtObject model
Component.onCompleted: {
root.view.anchors.fill = root
root.view.focus = true
}
}
main_window_presenter.qml 内容:
import "."
MyPresenter {
id: root
}
main.cpp 内容:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(":/qml/main_window_presenter.qml");
return app.exec();
}
当我运行应用程序时,我得到
QQmlApplicationEngine failed to load component
file::/qml/main_window_presenter.qml:1 import "." has no qmldir and no namespace
import "."
如果我在 main_window_presenter.qml删除,我会得到
QQmlApplicationEngine failed to load component
file::/qml/main_window_presenter.qml:3 MyPresenter is not a type
我认为我不需要导入语句,因为它们在同一个目录中。我在 meson.build 中使用带有相关部分的介子构建系统(之前定义了 exe_moc_headers):
qt5_module = import('qt5')
exe_processed = qt5_module.preprocess(moc_headers : exe_moc_headers, qresources : 'ui/resources.qrc')