QRemoteObject cannot acquire from Android service
Solved
Mobile and Embedded
-
Hi all
Basically I'm following this example: Android service example
I have rewritten this using widgets, but I cannot acquire remote object using QRemoteObjectadb logcat says that service is running and remoting is enabled
D/libservice.so( 8556): myapp-service.cpp:12 (MyAppSevice::MyAppSevice(QObject*)): qwerty enabled remoting D/libservice.so( 8556): myapp-service.cpp:33 (void MyAppSevice::timerTimeout()): qwerty srcNode lastError: QRemoteObjectNode::ErrorCode(NoError) count: 0 D/libservice.so( 8556): myapp-service.cpp:33 (void MyAppSevice::timerTimeout()): qwerty srcNode lastError: QRemoteObjectNode::ErrorCode(NoError) count: 1 D/libservice.so( 8556): myapp-service.cpp:33 (void MyAppSevice::timerTimeout()): qwerty srcNode lastError: QRemoteObjectNode::ErrorCode(NoError) count: 2 D/libservice.so( 8556): myapp-service.cpp:33 (void MyAppSevice::timerTimeout()): qwerty srcNode lastError: QRemoteObjectNode::ErrorCode(NoError) count: 3
but application debug says I'm connected to node, but cannot acquire PingPongReplica
D/OpenGLRenderer( 8515): Enabling debug mode 0 D/libmyapp.so( 8515): myapp.cpp:27 (MyApp::MyApp(QWidget*)): connected D/libmyapp.so( 8515): myapp.cpp:29 (MyApp::MyApp(QWidget*)): instances: () D/libmyapp.so( 8515): myapp.cpp:35 (MyApp::MyApp(QWidget*)): NOT acquired F/libmyapp.so( 8515): (null):0 ((null)): ASSERT: "res" in file myapp.cpp, line 37
If I uncomment part of server.cpp I can acquire PingPongReplica inside service - just like connect to myself?
What can be wrong, some hint please.
Best Regards
Marek//pingpong.h #include <QtCore> #include "rep_pingpong_source.h" class PingPong: public PingPongSource { public: PingPong(QObject *parent=0); public slots: void ping(const QString &msg) override; signals: void pong(const QString &msg); private slots: private: }; //pingpong.cpp PingPong::PingPong(QObject *parent):PingPongSource(parent) { } void PingPong::ping(const QString &msg) { emit QString("%1 reply from server").arg(msg); } //server.h class MyAppSevice: public QObject { Q_OBJECT public: MyAppSevice(QObject *parent=0); public slots: signals: private slots: void timerTimeout(); private: QRemoteObjectHost *srcNode; QTimer *timer; int count; PingPongReplica *rep2; QRemoteObjectNode *repNode; }; //server.cpp MyAppSevice::MyAppSevice(QObject *parent):QObject(parent) { count=0; PingPong pingPongServer; srcNode=new QRemoteObjectHost(QUrl(QStringLiteral("local:replica"))); if(srcNode->enableRemoting(&pingPongServer)) { qDebug()<<"qwerty enabled remoting"; /* repNode=new QRemoteObjectNode(QUrl(QStringLiteral("local:replica"))); qDebug()<<" instances:"<<repNode->instances<PingPongReplica>(); rep2=repNode->acquire<PingPongReplica>(); bool res = rep2->waitForSource(); if(res) { qDebug()<<" acquired qwerty"; } else { qDebug()<<" not acquired qwerty"; }*/ } else { qDebug()<<"not enabled qwerty"; } timer=new QTimer(this); timer->setInterval(1000); connect(timer,SIGNAL(timeout()),this,SLOT(timerTimeout())); timer->start(); } void AppSevice::timerTimeout() { qDebug()<<" qwerty srcNode lastError:"<<srcNode->lastError()<<" count:"<<count; count++; } //client.h class MyApp: public QMainWindow { Q_OBJECT public: MyApp(QWidget *parent=0); signals: private slots: private: Ui::MyApp *ui; PingPongReplica *rep2; QRemoteObjectNode *repNode; }; //client.cpp MyApp::MyApp(QWidget *parent) :QMainWindow(parent),ui(new Ui::MyApp) { ui->setupUi(this); repNode=new QRemoteObjectNode(this); if(!repNode->connectToNode(QUrl(QStringLiteral("local:replica")))) { qDebug()<<"NOT connected"; } else { qDebug()<<"connected"; } qDebug()<<" instances:"<<repNode->instances<PingPongReplica>(); rep2=repNode->acquire<PingPongReplica>(); bool res = rep2->waitForSource(); if(res) { qDebug()<<"acquired"; } else { qDebug()<<"NOT acquired"; } Q_ASSERT(res); };
-
//pingpong.h shouldn't also have signals defined, which are virtual and cannot have override keyword
class PingPong: public PingPongSource { public: PingPong(QObject *parent=0); public slots: void ping(const QString &msg) override; signals: private slots: private: };