Results 1 to 5 of 5

Thread: Architecture to eliminate "children and parent that is in a different thread"

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2020
    Posts
    9
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Architecture to eliminate "children and parent that is in a different thread"

    Quote Originally Posted by ChristianEhrlicher View Post
    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.

    Qt Code:
    1. class GreeterServiceImpl final : public Greeter::Service {
    2. public:
    3. Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* reply) override {
    4. // begin attempt 2
    5. QSslSocket mSocket;
    6. QSslConfiguration config = mSocket.sslConfiguration();
    7. config.setPeerVerifyMode(QSslSocket::VerifyNone);
    8. config.setProtocol(QSsl::SecureProtocols);
    9. mSocket.setSslConfiguration(config);
    10. mSocket.connectToHostEncrypted("google.com", 8080);
    11. // end attemt 2
    12. std::string prefix("Hello ");
    13. reply->set_message(prefix + request->name());
    14. return Status::OK;
    15. }
    16. };
    17.  
    18. void RunServer() {
    19. std::string server_address("0.0.0.0:50051");
    20. GreeterServiceImpl service;
    21. grpc::EnableDefaultHealthCheckService(true);
    22. grpc::reflection::InitProtoReflectionServerBuilderPlugin();
    23. ServerBuilder builder;
    24. builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
    25. builder.RegisterService(&service);
    26. std::unique_ptr<Server> server(builder.BuildAndStart());
    27. std::cout << "Server listening on " << server_address << std::endl;
    28. server->Wait();
    29. }
    30.  
    31. int main(int argc, char** argv) {
    32. QCoreApplication a(argc, argv);
    33. RunServer();
    34. return a.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QObject: Cannot create children for a parent that is in a different thread.
    2. (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.
    Qt Code:
    1. class GreeterServiceImpl final : public Greeter::Service, public QObject {
    2. Q_OBJECT
    3. public:
    4. Status SayHello(ServerContext* context, const HelloRequest* request, HelloReply* reply) override {
    5. std::string prefix("Hello ");
    6. reply->set_message(prefix + request->name());
    7. emit message();
    8. return Status::OK;
    9. }
    10. signals:
    11. void message();
    12. };
    To copy to clipboard, switch view to plain text mode 
    But it failed
    Qt Code:
    1. In function `GreeterServiceImpl::GreeterServiceImpl()':
    2. error: undefined reference to `vtable for GreeterServiceImpl'
    3. In function `GreeterServiceImpl::~GreeterServiceImpl()':
    4. error: undefined reference to `vtable for GreeterServiceImpl'
    5. error: collect2: error: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 
    Last edited by CPPProger; 24th June 2020 at 09:07.

Similar Threads

  1. Replies: 0
    Last Post: 16th June 2011, 21:48
  2. "new" + "delete" a QWidget and its children
    By vkincaid in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2010, 21:51
  3. Replies: 2
    Last Post: 7th September 2009, 21:13
  4. Replies: 6
    Last Post: 8th July 2009, 13:24
  5. Replies: 5
    Last Post: 19th April 2009, 13:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.