Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Custom QML module problem
Forum Update on Monday, May 27th 2025

Custom QML module problem

Scheduled Pinned Locked Moved Mobile and Embedded
11 Posts 5 Posters 10.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    horxpig
    wrote on 21 Mar 2012, 19:06 last edited by
    #1

    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 Script

    import 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 !

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on 21 Mar 2012, 19:27 last edited by
      #2

      Are you registering XXXX with your QDeclarativeContext the same way in both projects?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        horxpig
        wrote on 21 Mar 2012, 21:09 last edited by
        #3

        [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 :(

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on 21 Mar 2012, 21:11 last edited by
          #4

          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.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            horxpig
            wrote on 21 Mar 2012, 21:45 last edited by
            #5

            [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 :(

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on 21 Mar 2012, 21:53 last edited by
              #6

              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.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                task_struct
                wrote on 22 Mar 2012, 07:25 last edited by
                #7

                Hello,

                you can save/add contacts from QML. See "this thread":http://qt-project.org/forums/viewthread/14628/ for example.

                "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

                • Linu...
                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  horxpig
                  wrote on 22 Mar 2012, 14:06 last edited by
                  #8

                  [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 :)

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    horxpig
                    wrote on 22 Mar 2012, 14:29 last edited by
                    #9

                    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_NAMESPACE

                    ContactCreator::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
                    WriteUserData

                    CONFIG += mobility
                    MOBILITY += contacts

                    SOURCES +=
                    contactcreator.cpp

                    HEADERS +=
                    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 :/

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SanyStation
                      wrote on 5 Aug 2013, 11:45 last edited by
                      #10

                      [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.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Scorp1us
                        wrote on 18 May 2014, 18:14 last edited by
                        #11

                        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?

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved