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
Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1
Accepted Solution

problem with qmlRegisterType

Hi i have a problem with qmlRegister for the use of a signal onFarenheitChanged for my weather app, when i buid it and run it, doesnt have any problems except just that when the app starts it crash, with a message like this

 

Process 2016309487 (WeatherNow) terminated SIGSEGV code=2 fltno=11 ip=7844f196(/base/usr/lib/qt4/lib/libQtDeclarative.so.4.8.5@_ZN36QDeclarativePropertyValueInterceptorC1Ev+0x711) mapaddr=0014f196. ref=07a4f2f8 bdslot=1

 and this is the code

 

cpp

WeatherNowApp::WeatherNowApp()
{
	QCoreApplication::setOrganizationName("conias media");
	QCoreApplication::setApplicationName("WeatherNow");

	 qmlRegisterUncreatableType<bb::device::BatteryChargingState>("bb.device", 1, 0, "BatteryChargingState", "");
	 qmlRegisterType<QTimer>("My.Library", 1, 0, "QTimer");
	 qmlRegisterType<ExternalIP>("Network.ExternalIP", 1, 0, "ExternalIP");
     qmlRegisterType<WeatherNowApp>("Weather.Now", 1, 0, "WeatherNowApp");
	 //! [0]

 hpp

#ifndef WEATHERNOWAPP_HPP_
#define WEATHERNOWAPP_HPP_

#include <QtCore/QObject>
#include <bb/cascades/TabbedPane>
using namespace bb::cascades;

namespace bb
{
    namespace cascades
    {
        class Application;
    }
}

class WeatherNowApp : public QObject {
    Q_OBJECT

    Q_PROPERTY(bool useFarenheit READ useFarenheit WRITE setUseFarenheit NOTIFY useFarenheitChanged)

public:

    WeatherNowApp();
    Q_INVOKABLE void showPhotoInCard(const QString fileName);

Q_SIGNALS:
	void useFarenheitChanged();

 and the qml

 

import Weather.Now 1.0

attachedObjects: [
WeatherNowApp {
            onUseFarenheitChanged: {
                
            }
        }
]

 the qml is missing the changes for the label and that, but it doesnt work even withouth any code in there, so its not a problem on the internal code, any suggestions?

Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: problem with qmlRegisterType

The QML file should have a top-level object. "attachedObjects" is a property of the object.

If it's only a part of the QML file, please show the complete file + all error messages before SIGSEGV (if any) and getter/setter implementation.

Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: problem with qmlRegisterType

... also show any code you have in the constructor.

 

Later on you should change this to include the passing of the parent object so that it will be deleted properly.


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.
Please use plain text.
Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1

Re: problem with qmlRegisterType

this is the full error message

 

Qml debugging is enabled. Only use this in a safe environment!
OrientationSupportPrivate::getSupportedDisplayOrientation:  portrait 
OrientationSupportPrivate::initDirectionAndOrientation: 
   isCardOrViewer:  false 
   manifestDisplayOrientation: DisplayPortrait 
   displayOrientation: DisplayPortrait 
   uiOrientation: Portrait 
   displayDirection: North 
   nativeDisplayOrientation: Portrait 
CS Debugging enabled: false 
Cascades server initialized - waited for 72 milliseconds (real time) 

Process 2016309487 (WeatherNow) terminated SIGSEGV code=2 fltno=11 ip=7844f196(/base/usr/lib/qt4/lib/libQtDeclarative.so.4.8.5@_ZN36QDeclarativePropertyValueInterceptorC1Ev+0x711) mapaddr=0014f196. ref=07a4f2f8 bdslot=1

 and the qml

 

import bb.cascades 1.2
import QtMobilitySubset.location 1.1
import My.Library 1.0
import Network.ExternalIP 1.0
import Weather.Now 1.0
import bb.system 1.2
import bb.device 1.2
import bb.data 1.0

Page {
    
    property string latitude 
    property string longitude 
    property variant currentCoord

    property string newOrientation;

attachedObjects: [
 WeatherNowApp {
           onUseFarenheitChanged: {
               if (_WeatherNow.useFarenheit == true)    
                   weatherDataTemperature.text = Math.round((jsonweather.temp)*1.8+32);
               else {
                   weatherDataTemperature.text = Math.round(jsonweather.temp); 
               }
           }
       }
]

Container {
                    id: day0
                    horizontalAlignment: HorizontalAlignment.Fill
                    verticalAlignment: VerticalAlignment.Center
                    background: Color.Transparent
                    layout: StackLayout {

                    }
                    Label{
                        id: weatherDataTemperature
                        text: "" 
                        textStyle.fontWeight: FontWeight.W100
                        textStyle.fontSize: FontSize.PointValue
                        textStyle.fontSizeValue: 60
                        horizontalAlignment: HorizontalAlignment.Center
                        translationY: -60.0
                        translationX: 0
                        verticalAlignment: VerticalAlignment.Center
                        onTextChanged: {
                            if(jsonweather.temp<=0){
                                background.imageSource = "asset:///images/Backgrounds/Freezing.png"
                            }
                            else if(jsonweather.temp<=5){
                                background.imageSource = "asset:///images/Backgrounds/Colder.png"
                            }
                            else if(jsonweather.temp<=10){
                                background.imageSource = "asset:///images/Backgrounds/Cold.png"
                            }
                            else if(jsonweather.temp<=15){
                                background.imageSource = "asset:///images/Backgrounds/Littlecold.png"
                            }
                            else if(jsonweather.temp<=20){
                                background.imageSource = "asset:///images/Backgrounds/Fresh.png"
                            }
                            else if(jsonweather.temp<=25){
                                background.imageSource = "asset:///images/Backgrounds/Warm.png"
                            }
                            else if(jsonweather.temp<=30){
                                background.imageSource = "asset:///images/Backgrounds/Warmer.png"
                            }
                            else if(jsonweather.temp<=35){
                                background.imageSource = "asset:///images/Backgrounds/Hot.png"
                            }
                            else {
                                background.imageSource = "asset:///images/Backgrounds/Hotter.png"
                            }
                        }
                    }
}

 

 

Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: problem with qmlRegisterType

[ Edited ]

Any SIGSEGV error basically tells you that your app is writing RAM that doesn't belong to it or trying to execute a class method via an invalid pointer.

 

Am I correct in assuming that the WeatherNowApp class is your main app UI class? If so, I am confused why you would be registering it with QML and then attaching to a page in QML. It is not normal to register the main UI class to QML in the constructor of that same class with qmlRegisterType().

 

I think perhaps what you really want to do is pass the main app instance to QML as a context property. If you are trying to respond to a signal from your main UI class in QML, then you should do that with connect(). Something like this instead:

 

WeatherNowApp::WeatherNowApp()
{
	QCoreApplication::setOrganizationName("conias media");
	QCoreApplication::setApplicationName("WeatherNow");

	qmlRegisterUncreatableType<bb::device::BatteryChargingState>("bb.device", 1, 0, "BatteryChargingState", "");
	qmlRegisterType<QTimer>("My.Library", 1, 0, "QTimer");
	qmlRegisterType<ExternalIP>("Network.ExternalIP", 1, 0, "ExternalIP");

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

	// ---Make this app object available in QML
	qml->setContextProperty( "app", this );
}
Page {
   id: myPage
   function onUseFarenheitChanged() {
      if (_WeatherNow.useFarenheit == true)    
         weatherDataTemperature.text = Math.round((jsonweather.temp)*1.8+32);
      else {
         weatherDataTemperature.text = Math.round(jsonweather.temp); 
      }
   }
   onCreationCompleted: {
      app.useFarenheitChanged.connect(myPage.onUseFarenheitChanged);
   }
}

 

BTW, it doesn't make any difference to the code, but you mispelled fahrenheit.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: problem with qmlRegisterType

[ Edited ]

@greenmr Well spotted if this is indeed the case!

 

[Edit] If it's not this it's a very strange class name. :smileyhappy:


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.
Please use plain text.
Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1

Re: problem with qmlRegisterType

Yes!! That's exactly the problem, thanks @greenmr
Please use plain text.
Developer
edusal100
Posts: 108
Registered: ‎09-21-2013
My Device: Blackberry Z10 STL100-1

Re: problem with qmlRegisterType

@greenmr if I want to make an if on the refresh function I have on the swipe left code, to use just the function for change the units on change, and refresh the data if it hasn't change, how can I could use the useFarenheitChanged, or how can I do it?
Please use plain text.