Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
tsothcott
Posts: 30
Registered: ‎09-01-2013
My Device: Q5
Accepted Solution

qmlRegisterType - Main Class?

I'm trying to register a signal I have created in the main class of the application;

 

Q_SIGNALS:
    void completed(const int &regSuccess, const QString &loginUsername);

 

I have added this to the app.cpp;

 

qmlRegisterType<App>("Core.TheApp", 1, 0, "App");

 

App is the main class file, and is defined by

class App : public QObject

 

Now in my QML file i have;

import Core.TheApp 1.0

 

And I'm trying to call it like so;

 

 attachedObjects: [    
        
        App { 
          onCompleted {
//Do stuff 
}

        }

]

 

However I'm getting a NULL POINTER EXCEPTION.

 

Not quite sure what to do here :smileyhappy: thanks

 

Contributor
MegaStar
Posts: 12
Registered: ‎04-08-2013
My Device: Z10 Limited Edition STL100-1

Re: qmlRegisterType - Main Class?

Where you get Null Pointer Exception? Have you initialized the App class variables in its constructor?

Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: qmlRegisterType - Main Class?

[ Edited ]

You cannnot register App there is only one instance of application allowed.

By including it in attachedObjects you are trying to create a second instance of your app.

 

app (a pointer to the Application instance) is already passed as a property to the main qml file.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: qmlRegisterType - Main Class?

[ Edited ]

What you are trying to do will look something like this...

 

import bb.cascades 1.0

NavigationPane {
    
    Page {

    }

    onCreationCompleted: {        
        _app.completed.connect(outputBoo);
    }
    
    function outputBoo(success, username) {
        console.debug("Boo!");
    }

}

 

Where _app is defined in applicationui.cpp and passed as a property...

 

    QmlDocument *qml = QmlDocument::create("asset:///main.qml")
		.parent(this)
		.property("_app", this);

 

[Edit] Get rid of all the lines you wrote they aren't needed, apart from the signal one obviously.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.