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
Posts: 246
Registered: ‎09-30-2010
My Device: Z10, Onyx2
My Carrier: IND XL
Accepted Solution

Custom Class

ive create a new class for listening for phone call

 

/*
 * PhoneTools.cpp
 *
 *  Created on: 27 Jul 2014
 *      Author: anditsung
 */

#include "PhoneTools.hpp"

#include <QDebug>
#include <bb/system/phone/Phone>

using namespace bb::system::phone;

PhoneTools::PhoneTools(QObject *parent)
    : QObject(parent)
    , mPhone(new bb::system::phone::Phone)
{
    connect(mPhone, SIGNAL(callUpdated(const bb::system::phone::Call&)), SLOT(onCallUpdated(const bb::system::phone::Call&)));
    connect(mPhone, SIGNAL(callCommandResponseReceived(const bb::system::phone::CallCommandResponse&)), SLOT(onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse&)));
}

void PhoneTools::onCallUpdated(const bb::system::phone::Call &call) {
    qDebug() << "HASDFADFASDFASDFDASFADSFDASF ";
}

void PhoneTools::onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse &response) {
    qDebug() << "HASDFADFASDFASDFDASFADSFDASF ";
}

 

/*
 * PhoneTools.hpp
 *
 *  Created on: 27 Jul 2014
 *      Author: anditsung
 */

#ifndef PHONETOOLS_HPP_
#define PHONETOOLS_HPP_

#include <QObject>
#include <bb/system/phone/Phone>

class PhoneTools : public QObject {
    Q_OBJECT

public:
    PhoneTools(QObject *parent = 0);

private slots:
    void onCallUpdated(const bb::system::phone::Call&);
    void onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse&);

private:
    bb::system::phone::Phone *mPhone;
};


#endif /* PHONETOOLS_HPP_ */

i use it like this

 

/*
 * Copyright (c) 2011-2014 BlackBerry Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/LocaleHandler>
#include <bb/system/phone/Phone>

#include "PhoneTools.hpp"

using namespace bb::cascades;

ApplicationUI::ApplicationUI() :
        QObject()
{
    // prepare the localization
    m_pTranslator = new QTranslator(this);
    m_pLocaleHandler = new LocaleHandler(this);

    bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()));
    // This is only available in Debug builds
    Q_ASSERT(res);
    // Since the variable is not used in the app, this is added to avoid a
    // compiler warning
    Q_UNUSED(res);

    // initial load
    onSystemLanguageChanged();
    PhoneTools phoneTools;
    
    // Create scene document from main.qml asset, the parent is set
    // to ensure the document gets destroyed properly at shut down.
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // Create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    // Set created root object as the application scene
    Application::instance()->setScene(root);
}

void ApplicationUI::onSystemLanguageChanged()
{
    QCoreApplication::instance()->removeTranslator(m_pTranslator);
    // Initiate, load and install the application translation files.
    QString locale_string = QLocale().name();
    QString file_name = QString("TestPhoneManager_%1").arg(locale_string);
    if (m_pTranslator->load(file_name, "app/native/qm")) {
        QCoreApplication::instance()->installTranslator(m_pTranslator);
    }
}

 

its not working. not printing the debug to the console

 

but if i use it like this

 

/*
 * Copyright (c) 2011-2014 BlackBerry Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/LocaleHandler>
#include <bb/system/phone/Phone>

#include "PhoneTools.hpp"

using namespace bb::cascades;
using namespace bb::system::phone;

ApplicationUI::ApplicationUI() :
        QObject()
    , mPhone(new bb::system::phone::Phone)
{
    // prepare the localization
    m_pTranslator = new QTranslator(this);
    m_pLocaleHandler = new LocaleHandler(this);

    bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()));
    // This is only available in Debug builds
    Q_ASSERT(res);
    // Since the variable is not used in the app, this is added to avoid a
    // compiler warning
    Q_UNUSED(res);

    // initial load
    onSystemLanguageChanged();
    connect(mPhone, SIGNAL(callUpdated(const bb::system::phone::Call&)), SLOT(onCallUpdated(const bb::system::phone::Call&)));
    connect(mPhone, SIGNAL(callCommandResponseReceived(const bb::system::phone::CallCommandResponse&)), SLOT(onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse&)));

    // Create scene document from main.qml asset, the parent is set
    // to ensure the document gets destroyed properly at shut down.
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // Create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    // Set created root object as the application scene
    Application::instance()->setScene(root);
}

void ApplicationUI::onCallUpdated(const bb::system::phone::Call &call) {
    qDebug() << "HELOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO";
}

void ApplicationUI::onCallCommandResponseReceived(const bb::system::phone::CallCommandResponse &callCommandResponse) {

}

void ApplicationUI::onSystemLanguageChanged()
{
    QCoreApplication::instance()->removeTranslator(m_pTranslator);
    // Initiate, load and install the application translation files.
    QString locale_string = QLocale().name();
    QString file_name = QString("TestPhoneManager_%1").arg(locale_string);
    if (m_pTranslator->load(file_name, "app/native/qm")) {
        QCoreApplication::instance()->installTranslator(m_pTranslator);
    }
}

 it was working.. what do i do wrong in this?

 

 

 

 

 

 

 

 

 

 

 

 

Developer
Posts: 230
Registered: ‎01-12-2013
My Device: z30
My Carrier: Mobile Vikings

Re: Custom Class

Have you checked if the connect methods return true in the PhoneTools constructor?

 

Also, try to create the Phonetools object like this

 

PhoneTools *tools = new PhoneTools(this);

 

______________________________________________________
BB10-OAuth: GitHub
Highlighted
Developer
Posts: 161
Registered: ‎01-03-2013
My Device: n/a
My Carrier: n/a

Re: Custom Class

[ Edited ]

Since you're creating the object as "automatic" and as soon as it gets out of scope it's destroyed. its destructor is called and due to this, the connections are also destroyed (There are no slots to call anymore). Realize that the mPhone object is not destroyed, it's a dangling pointer.

Regards.

If my answer has been useful to you, please, click the button