[Development] QtRemoteObjects: unable to retrieve the slot return value
Laszlo Papp
lpapp at kde.org
Sat Oct 28 14:25:09 CEST 2023
Hi,
I am unable to retrieve the slot return value from the host to the replica.
You can find the testbed below that reproduces the issue.
FooService is the QtRemoteObject host and BarService is the replica. The
slot on the host (Foo) does get called initiated from the replica (Bar),
but waitForService on the replicate times out with false rather than true.
Any ideas what it could be?
*FooService.rep*
class FooService
{
SLOT(int requestFoo());
};
*FooService.h*
#ifndef FOOSERVICE_H
#define FOOSERVICE_H
#include "rep_FooService_source.h"
class FooService : public FooServiceSimpleSource
{
Q_OBJECT
public:
FooService(QObject *parent = nullptr);
int requestFoo() override;
};
#endif
*FooService.cpp*
#include "FooService.h"
FooService::FooService(QObject *parent)
: FooServiceSimpleSource(parent)
{
}
int FooService::requestFoo()
{
qDebug() << "Server: requestFoo() called";
return 666;
}
*foo.cpp*
#include "FooService.h"
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
FooService fooService;
QRemoteObjectHost sourceNode(QUrl(QStringLiteral("local:foo")));
sourceNode.enableRemoting(&fooService);
return a.exec();
}
*BarService.h*
#ifndef BARSERVICE_H
#define BARSERVICE_H
#include <QObject>
#include <QSharedPointer>
#include "rep_FooService_replica.h"
class BarService : public QObject
{
Q_OBJECT
public:
BarService();
private:
QRemoteObjectNode repNode;
QSharedPointer<FooServiceReplica> reptr;
};
#endif
*BarService.cpp*
#include "BarService.h"
BarService::BarService()
: QObject(nullptr)
{
repNode.connectToNode(QUrl(QStringLiteral("local:foo")));
reptr.reset(repNode.acquire<FooServiceReplica>());
QObject::connect(reptr.data(), &FooServiceReplica::initialized, this,
[this]() {
qDebug() << "TEST IS INITIALIZED: " << reptr.data()->isInitialized();
qDebug() << "TEST IS VALID: " << reptr.data()->isReplicaValid();
QRemoteObjectPendingReply<int> call = reptr.data()->requestFoo();
qDebug() << "TEST ERROR: " << call.error();
qDebug() << "TEST WAIT FOR FINISHED: " << call.waitForFinished(1000);
qDebug() << "TEST RETURN VALUE: " << call.returnValue();
});
}
*bar.cpp*
#include "BarService.h"
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
BarService barService;
return a.exec();
}
*CMakeLists.txt*
cmake_minimum_required(VERSION 3.16)
project(foo LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt6 COMPONENTS Core RemoteObjects QUIET)
qt_standard_project_setup()
##### Server #####
add_executable(FooService WIN32 MACOSX_BUNDLE FooService.cpp foo.cpp)
target_link_libraries(FooService PRIVATE Qt::RemoteObjects)
qt_add_repc_sources(FooService FooService.rep)
##### Client #####
add_executable(BarService WIN32 MACOSX_BUNDLE BarService.cpp bar.cpp)
target_link_libraries(BarService PRIVATE Qt::RemoteObjects)
qt_add_repc_replicas(BarService FooService.rep)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20231028/06bc6a68/attachment.htm>
More information about the Development
mailing list