Custom QML module problem
-
wrote on 21 Mar 2012, 19:06 last edited by
Hi!
I am developing an application for meego where i need to save contacts to the phone address book, so far i've managed to create a C++ class that can save a contact and it's implemented into the QML code, I first did it in a new project to test it and it worked perfectly fine, but when i tried to add it to my actual application it says: "Module XXXX is not installed", my guess is that some other module is causing my custom module to fail :(
in my QML file i am importing the following modules:
import QtQuick 1.1
import com.meego 1.0
import QtMobility.systeminfo 1.1
import QtMobility.contacts 1.1
import QtMobility.location 1.2
import "script.js" as Scriptimport XXXX 1.0
Also my C++ Class inherits QObject and implements namespace QtMobility and the following classes:
#include <QContactManager>
#include <QContactName>
#include <QContactPhoneNumber>
#include <QContactEmailAddress>As i said, in a clear project it works perfectly fine, but when i use it in my real project exactly as i did in the test project it fails :(
Thanks in advance !
-
wrote on 21 Mar 2012, 19:27 last edited by
Are you registering XXXX with your QDeclarativeContext the same way in both projects?
-
wrote on 21 Mar 2012, 21:09 last edited by
[quote author="mlong" date="1332358065"]Are you registering XXXX with your QDeclarativeContext the same way in both projects?
[/quote]Yes, in both projects I'm using:
qmlRegisterType<XXXX>("XXXX", 1, 0, "XXXX");
exactly in the same way, qml does recognize the module when i'm typing the code, but when i try to build it, it says it's not installed :(
-
wrote on 21 Mar 2012, 21:11 last edited by
You also want to make sure that you register your type before you set the QML source file. I've been caught by that one before.
-
wrote on 21 Mar 2012, 21:45 last edited by
[quote author="mlong" date="1332364312"]You also want to make sure that you register your type before you set the QML source file. I've been caught by that one before.[/quote]
It is registered before, I think the problem might be more on the QML side, but I'm out of ideas :(
-
wrote on 21 Mar 2012, 21:53 last edited by
Without seeing code, I don't think there's a lot anyone can do. Can you create a small sample snippet which contains the pertinent sections of code from where you do your registration in both the test and production code? The key will lie someone where in the differences between the apps.
-
wrote on 22 Mar 2012, 07:25 last edited by
Hello,
you can save/add contacts from QML. See "this thread":http://qt-project.org/forums/viewthread/14628/ for example.
-
wrote on 22 Mar 2012, 14:06 last edited by
[quote author="task_struct" date="1332401107"]Hello,
you can save/add contacts from QML. See "this thread":http://qt-project.org/forums/viewthread/14628/ for example.[/quote]
That doesn't work on meego for some reason, it just creates a blank contact but it doesn't add the information to it, that's why I'm doing it on a C++ class. thanks anyway :)
-
wrote on 22 Mar 2012, 14:29 last edited by
My code is basically something like this in both apps:
(ContactCreator is my XXXX class)
In my ContactCreator.h:
@
#ifndef CONTACTCREATOR_H
#define CONTACTCREATOR_H#include <QObject>
class ContactCreator : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE bool contacto(QString nombre,QString email);
explicit ContactCreator(QObject *parent = 0);};#endif // CONTACTCREATOR_H
@ContacCreator.cpp
@
#include "contactcreator.h"
#include <QContactManager>
#include <QContactName>
using namespace QtMobility;
QTM_USE_NAMESPACEContactCreator::ContactCreator(QObject *parent) : QObject(parent){}
bool ContactCreator::contacto(QString nombre, QString correo){
QContactManager *cm = new QContactManager();
QContact example;
QContactName nomi;
nomi.setFirstName(correo);
nomi.setLastName(nombre);
example.saveDetail(&nomi);
bool resp;
if(cm->saveContact(&example)){
resp = true;
}else{
resp = false;
}
return resp;
}
@In my Pro file i added:
@
symbian::TARGET.CAPABILITY =
ReadUserData
ReadDeviceData
ReadUserData
WriteUserDataCONFIG += mobility
MOBILITY += contactsSOURCES +=
contactcreator.cppHEADERS +=
contactcreator.h
@And finally in the qmlapplicationviewer.cpp i modified the following:
@// Enable debugging before any QDeclarativeEngine is created
struct QmlJsDebuggingEnabler
{
QmlJsDebuggingEnabler()
{
QDeclarativeDebugHelper::enableDebugging();
}
};
@
To be like this:
@
#include "../contactcreator.h"
// Enable debugging before any QDeclarativeEngine is created
struct QmlJsDebuggingEnabler
{
QmlJsDebuggingEnabler()
{
QDeclarativeDebugHelper::enableDebugging();
qmlRegisterType<ContactCreator>("ContactCreator", 1, 0, "ContactCreator");
}
};
@So now in my QML I call:
@
import ContactCreator 1.0[...Some qml code...]
ContactCreator{
id: contCreator
Component.onCompleted:{
contCreator.contacto("TestLastName","TestName");
}
}
@I did it exactly the same in both apps and it only fails in one of them :/
-
wrote on 5 Aug 2013, 11:45 last edited by
[quote author="mlong" date="1332364312"]You also want to make sure that you register your type before you set the QML source file. I've been caught by that one before.[/quote]
Thanks. You helped me a lot.
-
wrote on 18 May 2014, 18:14 last edited by
I am trying to port a 4.7 class to 5.x, and I'm having this problem. However, its not a visual component, It is a QAbstractItemModel derived component. What is the resolution for that?