I wanted to create a new QML type from C++ but I encountered a problem in the process, which I couldn't resolve. I have a class in C++ - "Mytype" - which has been registered with the QML Type System via qmlregistertype function.
So far so good. The class was correctly registered and the application run fine on desktop environments, everything worked fine. However, when I built and deployed the application to an Android device, I received the following error:
Warning: QML import could not be resolved in any of the import paths: Mytype
What does this error talk about? What could be the reason for this error? How can I fix it? Please, help me. Here follows a simplified code example:
#include <QApplication>
#include <QQmlApplicationEngine>
#include "mytype.h"
int main(int argc, char *argv[])
{
qmlRegisterType<Mytype>("mytype", 1, 0, "Mytype");
QQmlApplicationEngine engine;
engine.
load(QUrl(QStringLiteral
("qrc:/main.qml")));
return app.exec();
}
#include <QApplication>
#include <QQmlApplicationEngine>
#include "mytype.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qmlRegisterType<Mytype>("mytype", 1, 0, "Mytype");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
To copy to clipboard, switch view to plain text mode
import mytype 1.0;
...
Mytype {
id: my_type;
...
}
import mytype 1.0;
...
Mytype {
id: my_type;
...
}
To copy to clipboard, switch view to plain text mode
Bookmarks