2012-11-05 1 views
2

Blackberry 10 Dev Alpha Simulator 및 QNX Momentics IDE와 함께 C++ QT & QML과 함께 Blackberry Cascades 10 Beta 3 SDK를 사용하고 있습니다. QML의 전화 번호가있는 단추를 클릭하고 해당 번호의 다이얼 패드를 불러올 수있는 기능. 사용자는 전화를 걸 수 있어야하며 전화를 걸 수 있어야합니다. 다음은 내가했던 일의 종류입니다 :블랙 베리 캐스케이드에서 특정 번호의 폰 패드를 표시하는 방법

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 
} 

내가 가지고 을 ...

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); 
} 

을하지만 난 클릭 할 때 버튼은 아무 것도하지 않습니다 - 나는 다이얼 패드가 필요합니다 - 다른 사람들이 내가 뭘 잘못하고 있는지 알고 있습니까?

+0

당신의 궁금 - 그래서의 문제가 아니다 - 전화에 같은 QML 문서에서 호출 할 수 있습니다 - 휴대 전화에있는 것과 같은 동급의 다른 Q_INVOKABLE 멤버 함수 클래스가 특정 변수를 통해 해당 특정 qml 문서에 등록되지 않았거나 올바른 변수 이름을 사용하여 onClicked 이벤트 핸들러의 qml에서 해당 클래스를 참조하지 않는 문제가 발생했습니다 – user1296259

+0

'qmlRegisterType '을 사용하여 Foo 클래스는 QML에서 사용할 수 있습니까? – donturner

+0

예, qmlRegisterType을 사용 중입니다. user1296259

답변

2

변경 다음 수업 푸의 코드 :

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 코드를 통해 그것을 노출하여 앱 :

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

가 다음처럼 QML에서 사용 :

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

추가됨 : 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