
Originally Posted by
ChristianEhrlicher
You still don't create the socket in the run thread but in the main thread...
Directly inside the gRPC method, the socket also does not want to work.
class GreeterServiceImpl final : public Greeter::Service {
public:
Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* reply) override {
// begin attempt 2
QSslSocket mSocket;
QSslConfiguration config = mSocket.sslConfiguration();
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(QSsl::SecureProtocols);
mSocket.setSslConfiguration(config);
mSocket.connectToHostEncrypted("google.com", 8080);
// end attemt 2
std::string prefix("Hello ");
reply->set_message(prefix + request->name());
return Status::OK;
}
};
void RunServer() {
std::string server_address("0.0.0.0:50051");
GreeterServiceImpl service;
grpc::EnableDefaultHealthCheckService(true);
grpc::reflection::InitProtoReflectionServerBuilderPlugin();
ServerBuilder builder;
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl;
server->Wait();
}
int main(int argc, char** argv) {
RunServer();
return a.exec();
}
class GreeterServiceImpl final : public Greeter::Service {
public:
Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* reply) override {
// begin attempt 2
QSslSocket mSocket;
QSslConfiguration config = mSocket.sslConfiguration();
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(QSsl::SecureProtocols);
mSocket.setSslConfiguration(config);
mSocket.connectToHostEncrypted("google.com", 8080);
// end attemt 2
std::string prefix("Hello ");
reply->set_message(prefix + request->name());
return Status::OK;
}
};
void RunServer() {
std::string server_address("0.0.0.0:50051");
GreeterServiceImpl service;
grpc::EnableDefaultHealthCheckService(true);
grpc::reflection::InitProtoReflectionServerBuilderPlugin();
ServerBuilder builder;
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl;
server->Wait();
}
int main(int argc, char** argv) {
QCoreApplication a(argc, argv);
RunServer();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
QObject: Cannot create children
for a parent that is in a different thread.
(Parent is QSslSocket(0x556688f2a520), parent's thread is QThread(0x556688f23800), current thread is QThread(0x7fe7a8004510)
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QSslSocket(0x556688f2a520), parent's thread is QThread(0x556688f23800), current thread is QThread(0x7fe7a8004510)
To copy to clipboard, switch view to plain text mode
Added after 21 minutes:
I also tried to connect Qt and gRPC with the inclusion of a signal in the server. The latter would help connect the two frameworks.
class GreeterServiceImpl final
: public Greeter
::Service,
public QObject {Q_OBJECT
public:
Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* reply) override {
std::string prefix("Hello ");
reply->set_message(prefix + request->name());
emit message();
return Status::OK;
}
signals:
void message();
};
class GreeterServiceImpl final : public Greeter::Service, public QObject {
Q_OBJECT
public:
Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* reply) override {
std::string prefix("Hello ");
reply->set_message(prefix + request->name());
emit message();
return Status::OK;
}
signals:
void message();
};
To copy to clipboard, switch view to plain text mode
But it failed
In function `GreeterServiceImpl::GreeterServiceImpl()':
error: undefined reference to `vtable for GreeterServiceImpl'
In function `GreeterServiceImpl::~GreeterServiceImpl()':
error: undefined reference to `vtable for GreeterServiceImpl'
error: collect2: error: ld returned 1 exit status
In function `GreeterServiceImpl::GreeterServiceImpl()':
error: undefined reference to `vtable for GreeterServiceImpl'
In function `GreeterServiceImpl::~GreeterServiceImpl()':
error: undefined reference to `vtable for GreeterServiceImpl'
error: collect2: error: ld returned 1 exit status
To copy to clipboard, switch view to plain text mode
Bookmarks