"is not a type" error when importing custom qml from resource
-
I have the following directory structure:
ui/ |- resources.qrc |- qml/ |- main_window.qml |- ControlUnitListPresenter.qml
resources.qrc contents:
<RCC> <qresource prefix="/"> <file>qml/ControlUnitListPresenter.qml</file> <file>qml/main_window.qml</file> </qresource> </RCC>
main_window.qml contents:
import QtQuick 2.11 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.11 ApplicationWindow { visible: true visibility: "Maximized" menuBar: MenuBar { Menu { title: "File" MenuItem { text: "Open" } MenuItem { text: "Save" } } } ControlUnitListPresenter { } }
main.cpp contents:
int main(int argc, char **argv) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(":/qml/main_window.qml"); return app.exec(); }
When I run the application I get:
QQmlApplicationEngine failed to load component file::/qml/main_window.qml:22 ControlUnitListPresenter is not a type
I don't think I need an import statement because they are in the same directory.
-
I have the following directory structure:
ui/ |- resources.qrc |- qml/ |- main_window.qml |- ControlUnitListPresenter.qml
resources.qrc contents:
<RCC> <qresource prefix="/"> <file>qml/ControlUnitListPresenter.qml</file> <file>qml/main_window.qml</file> </qresource> </RCC>
main_window.qml contents:
import QtQuick 2.11 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.11 ApplicationWindow { visible: true visibility: "Maximized" menuBar: MenuBar { Menu { title: "File" MenuItem { text: "Open" } MenuItem { text: "Save" } } } ControlUnitListPresenter { } }
main.cpp contents:
int main(int argc, char **argv) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(":/qml/main_window.qml"); return app.exec(); }
When I run the application I get:
QQmlApplicationEngine failed to load component file::/qml/main_window.qml:22 ControlUnitListPresenter is not a type
I don't think I need an import statement because they are in the same directory.
@Alp-Hancioglu said in "is not a type" error when importing custom qml from resource:
I don't think I need an import statement because they are in the same directory.
not that i am aware of, try add
import "."
-
import "."
gave me
QQmlApplicationEngine failed to load component file::/qml/main_window.qml:4 import "." has no qmldir and no namespace
By the way I am using meson as build system instead of qmake if it makes any difference. It shouldn't because meson also uses rcc.
-
import "."
gave me
QQmlApplicationEngine failed to load component file::/qml/main_window.qml:4 import "." has no qmldir and no namespace
By the way I am using meson as build system instead of qmake if it makes any difference. It shouldn't because meson also uses rcc.
@Alp-Hancioglu
strange.import "."
normally doesn't require a qmldir file.Try to load load your ui with an QUrl instead of a filepath:
engine.load( QUrl("qrc:/qml/main_window.qml") );
-
import "."
gave me
QQmlApplicationEngine failed to load component file::/qml/main_window.qml:4 import "." has no qmldir and no namespace
By the way I am using meson as build system instead of qmake if it makes any difference. It shouldn't because meson also uses rcc.
@Alp-Hancioglu said in "is not a type" error when importing custom qml from resource:
meson
I don't have experience with meson, but with qmake, you'll have to rerun qmake after adding a qml file to the ressource file. Because the ressource file is not recreated each time you add or remove components.
-
engine.load( QUrl("qrc:/qml/main_window.qml") );
works. There is no need for import. Thanks.