Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QRemoteObject cannot acquire from Android service
Forum Updated to NodeBB v4.3 + New Features

QRemoteObject cannot acquire from Android service

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 1 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marek
    wrote on last edited by
    #1

    Hi all

    Basically I'm following this example: Android service example
    I have rewritten this using widgets, but I cannot acquire remote object using QRemoteObject

    adb 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);
    };
    
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Marek
      wrote on last edited by
      #2

      Ok, its my fault,
      in server.cpp PingPongServer goes out of scope and thats why I couldn't acquire.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Marek
        wrote on last edited by
        #3

        //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:
        };
        
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved