如何在Blackberry Cascades中显示具有特定编号的电话板 [英] How to show a phonepad with a certain number in Blackberry Cascades

查看:105
本文介绍了如何在Blackberry Cascades中显示具有特定编号的电话板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Blackberry Cascades 10 Beta 3 SDK与C ++ QT&带有Blackberry 10 Dev Alpha Simulator和QNX Momentics IDE的QML,我正在尝试实现单击带有来自QML的电话号码的按钮的功能,并让其从该位置调出带有该号码的拨号盘.用户应该可以按通话键,它将拨打该号码.以下是我已经完成的事情:

I am using Blackberry Cascades 10 Beta 3 SDK with C++ QT & QML with the Blackberry 10 Dev Alpha Simulator and the QNX Momentics IDE, and I'm trying to implement the ability to click on a button with a phone number from QML and have it bring up a dialpad with that number in from at which point the user should be able to press call and it would call that number. The following is the sort of thing I have done:

Button {
    text: "555-555-5555" //just a sample number - I don't actually use this number
    onClicked: Foo.phone(text) //I don't actually use the class name Foo
}

,我有: ...

and I have: ...

class Foo : public QObject {
    Q_OBJECT
public:
    ...
    Q_INVOKABLE void phone(QString number);
}
...

我有:

void Foo::phone(QString number) {
    bb::system::phone::Phone phone;
    phone.requestDialpad(number, bb::system::phone::LineType::Cellular);
}

但是当我单击按钮时,它什么也没做-我需要显示拨号盘-有人知道我在做什么错吗?

But when I click on the button it doesn't do anything - I need the dialpad to show up - does anyone have any idea what I'm doing wrong?

推荐答案

将类Foo的代码更改为以下代码:

Change the code of your class Foo to the following:

Foo.hpp

#ifndef FOO_HPP_
#define FOO_HPP_

#include <QObject>
#include <bb/system/InvokeManager>

class Foo : public QObject {
    Q_OBJECT

public:
    Foo();
    virtual ~Foo();

    Q_INVOKABLE void callNumber(const QString& number);

private Q_SLOTS:
    void processInvokeReply(); // This slot handles the result of an invocation

private:
    bb::system::InvokeManager* _invokeManager;

    Q_DISABLE_COPY(Foo);
};
#endif /* FOO_HPP_ */

Foo.cpp:

#include <bb/system/InvokeAction>
#include <bb/system/InvokeReply>
#include <bb/system/InvokeTargetReply>
#include <bb/system/InvokeRequest>
#include <bb/PpsObject>
#include "Foo.hpp"

Foo::Foo() :
        _invokeManager(new InvokeManager(this)) {
}


Foo::~Foo() {
}

void Foo::processInvokeReply() {
    InvokeReply *reply = qobject_cast<InvokeReply*>(sender());     // Get the reply from the sender object

    // Check for errors during invocation
    switch (reply->error()) {
        case InvokeReplyError::BadRequest:
                qDebug("[ErrorBadRequest] Invoke Failed!");
            break;
        case InvokeReplyError::Internal:
                qDebug("[ErrorInternal] Invoke Failed!");
            break;
        case InvokeReplyError::NoTarget:
                qDebug("[ErrorNoTarget] Invoke Failed!");
            break;
        case InvokeReplyError::TargetNotOwned:
                qDebug("[ErrorTargetNotOwned] Invoke Failed.");
            break;
        default:
                qDebug("[Odd Error %d] Invoke failed", reply->error());
            break;
    }
    reply->deleteLater();     // Delete the reply later on
}


void Foo::callNumber(const QString& number) {
    QVariantMap map;
    map.insert("number", number);    // required
    QByteArray requestData = bb::PpsObject::encode(map, NULL);
    InvokeRequest request;
    request.setAction("bb.action.DIAL");
    request.setData(requestData);
    request.setMimeType("application/vnd.blackberry.phone.startcall");
    const InvokeTargetReply *reply = _invokeManager->invoke(request);
    if (reply) {
        QObject::connect(reply, SIGNAL(finished()), this, SLOT(processInvokeReply()));
    } else {
        qWarning() << "Invoke Failed! InvokeReply is empty.";
    }
}

通过初始化cpp代码将其暴露在启动应用的位置:

Expose it via initialisation cpp code where you launch your app:

Foo* _foo = new Foo();
qml->setContextProperty("_foo", _foo);

然后像这样在QML中使用它:

Then use it in QML like that:

Button {
    onClicked: {
        _foo.callNumber("555-555-5555")
    }
}

添加:

此外,还有一种更简便的方法:

Also, there's an easier way for doing this:

在main.cpp中:

in main.cpp:

#include <bb/system/phone/Phone>
#include <bb/data/DataSource>

// skipped ...

Q_DECL_EXPORT int main(int argc, char **argv)
{
     // ...skipped 
        qmlRegisterType<bb::system::phone::Phone>("bb.system.phone", 1, 0, "Phone");
        bb::data::DataSource::registerQmlTypes();
     // ...skipped
}

然后在QML文件中:

import bb.cascades 1.0
import bb.system.phone 1.0

// Creates one page with a button. When you tap the button,
// a dial pad with a specific phone number is displayed.

Page {
    Container {
        layout: DockLayout {
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center

        Button {
            id: callButton
            text: "Call me, maybe"

            onClicked: {
                phone.requestDialpad("(519) 555-0100")
            }
        }
    }
    attachedObjects: [
        Phone {
            id: phone
        }
    ]
}

在此处详细了解此示例- http://developer.blackberry .com/cascades/documentation/device_comm/phone/index.html

Read more about this example here - http://developer.blackberry.com/cascades/documentation/device_comm/phone/index.html

这篇关于如何在Blackberry Cascades中显示具有特定编号的电话板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆