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:
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
#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
#ifndef APP_H
#define APP_H
#include <QTimer>
#include "qtquick2applicationviewer.h"
class cAppChild : public QObject
{
Q_OBJECT
QTimer timer;
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
To copy to clipboard, switch view to plain text mode
app.cpp
#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;
}
#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;
}
To copy to clipboard, switch view to plain text mode
main.cpp
#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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
qml/provaintegrazione/main.qml
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"
}
}
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"
}
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks