Problems with QtQuick wizard generated project
Hello,
I'm trying to add a C++ defined type to a simple QML file, but when I start debugging the application I receive the following error: "module "APP_CHILD" is not installed
import APP_CHILD 1.0".
The application I'm running is derived from a wizard generated QtQuick application which is meant to handle native system events some way.
The program is structured as follows:
Quote:
qtquick2applicationviewer/qtquick2applicationviewer.cpp (Wizard generated)
qtquick2applicationviewer/qtquick2applicationviewer.h (Wizard generated)
qtquick2applicationviewer/qtquick2applicationviewer.pri (Wizard generated)
qml/provaintegrazione/main.qml
app.cpp
app.h
main.cpp
provaintegrazione.pro
provaintegrazione.pro.user
and this is the code of the files I modified by myself:
app.h
Code:
#ifndef APP_H
#define APP_H
#include <QTimer>
#include "qtquick2applicationviewer.h"
{
Q_OBJECT
bool check;
public:
cAppChild();
virtual ~cAppChild(){}
private slots:
void change(){ check = !check; timer.start(); }
};
class cApp : public QtQuick2ApplicationViewer
{
Q_OBJECT
bool nativeEvent
(const QByteArray &eventType,
void *message,
long *result
);
public:
explicit cApp(QWindow *parent = 0);
virtual ~cApp();
};
#endif // APP_H
app.cpp
Code:
#include <QtDeclarative>
#include "app.h"
cAppChild::cAppChild()
{
check = false;
timer.start();
//Connections for attach/detach notification
connect(&timer, SIGNAL(timeout()), this, SLOT(change()));
}
cApp::cApp(QWindow *parent) : QtQuick2ApplicationViewer(parent)
{
}
cApp::~cApp()
{
}
bool cApp
::nativeEvent(const QByteArray &eventType,
void *message,
long *result
) {
if( eventType == "windows_generic_MSG" )
{
// Some kind of event handling.
}
return false;
}
main.cpp
Code:
#include <QtGui/QGuiApplication>
#include <QtDeclarative>
#include "app.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<cAppChild>("APP_CHILD", 1, 0, "appchild");
cAppChild myApp;
cApp viewer;
viewer.setMainQmlFile(QStringLiteral("qml/provaintegrazione/main.qml"));
viewer.showExpanded();
return app.exec();
}
qml/provaintegrazione/main.qml
Code:
import QtQuick 2.0
import QtQuick.Controls 1.0
import APP_CHILD 1.0
ApplicationWindow
{
id: main_window
Rectangle
{
id: pippo
width: 360
height: 360
color: "red"
}
}
Can anybody try to use the code above on his QtCreator and explain me how to make the qml code recognize the APP_CHILD module?
Re: Problems with QtQuick wizard generated project
That looks OK. Are you sure you are running the actual application, not just "running" the QML file?
Cheers,
_
Re: Problems with QtQuick wizard generated project
I didn't understand your question. The QML file should act as UI and use my C++ class registered as a new QML type. Now the main.cpp file was created by the QtCreator wizard, I just added the type registration for QML and used a class inherited by the class within qtquick2applicationviewer.h in order to use my own nativeEvent() function in the future. What I don't understand is why the import statement inside main.qml file is not recognized. Could you please try to create a QtQuick project like this, add my files and see if everything works on your side? Maybe an experienced Qt programmer like you could understand the problem better than I can do.
Re: Problems with QtQuick wizard generated project
Quote:
Originally Posted by
enrico5th
I didn't understand your question.
you wrote "when I start debugging" and I was asking what exactly you were doing.
Did you run the application or just "run" the QML file.
Quote:
Originally Posted by
enrico5th
What I don't understand is why the import statement inside main.qml file is not recognized.
It should, hence my question to narrow down possible errors.
Quote:
Originally Posted by
enrico5th
Could you please try to create a QtQuick project like this, add my files and see if everything works on your side? Maybe an experienced Qt programmer like you could understand the problem better than I can do.
I can do that if you attach a buildable example.
Cheers,
_
1 Attachment(s)
Re: Problems with QtQuick wizard generated project
I run the whole application.
You can find the whole project attached to this post.
1 Attachment(s)
Re: Problems with QtQuick wizard generated project
After I got it to build, it worked for me.
Attachment 10131
Cheers,
_
Re: Problems with QtQuick wizard generated project
Does it work without any modification? When I build and run it, a little white window appears on the screen (instead of a big red rectangle), then I look at the Application Output window and the message "module "APP_CHILD" is not installed import APP_CHILD 1.0" has been output there. I tried on two different platform and I got the same problem. I'm now asking to myself what's the difference between my platform and yours.
Re: Problems with QtQuick wizard generated project
Lets try with a very simple example
main.cpp
Code:
#include <QtQml>
int main(int argc, char **argv)
{
qmlRegisterType<QTimer>("APP_CHILD", 1, 0, "AppChild");
QQmlEngine engine;
QQmlComponent component(&engine);
component.
setData("import APP_CHILD 1.0\n\nAppChild { }",
QUrl());
qDebug() << "created object=" << component.create();
return 0;
}
appchildtest.pro
Code:
TEMPLATE = app
TARGET = appchildtest
INCLUDEPATH += .
# Input
SOURCES += main.cpp
QT += qml
Executing that should give you an output like this:
created object= QTimer(0xc2b250)
Once you've veryfied that, add you class and register it instead of QTimer.
Cheers,
_
Re: Problems with QtQuick wizard generated project
Your example works perfectly, this makes me think there's some problem in the way I've attached the main.qml file in my project. But that was done automatically by the Qt Quick wizard for projects creation. This thing is making me crazy!!!
Re: Problems with QtQuick wizard generated project
Have you tried running the program from a terminal/shell?
Just to make sure you are actually running the program, not just "running" the QML file.
Cheers,
_