drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.44k stars 1.1k forks source link

What is the best way to integrate drogon into Qt client programs? 将drogon集成到Qt客户端程序中,使用什么方式更好? #2121

Closed MiQter closed 1 month ago

MiQter commented 1 month ago

What is the recommended way to integrate the drogon framework into Qt client programs to enable them to have HTTP service functionality.推荐使用什么方式,将drogon框架集成到Qt客户端程序中,使得Qt客户端程序具有http服务的功能。

MiQter commented 1 month ago

The first method is to use the Qt QThread class, write a derived class of QThread, overload the run function of QThread, and call the app (). run() function of drogon in the run function. 第一种方法是使用Qt QThread类,编写QThread派生类,重载QThread的run函数,在run函数中调用drogon的app().run()函数。

        class httpServerThread:public QThread
        {
        protected:
            void run()
            {
                app().loadConfigFile("./config.json").run();
            }
        }
        httpServerThread * subThread = new httpServerThread;
        subThread->start();

The second method is to use std:: thread from the C++standard library. 第二种方法,是使用C++标准库的std::thread。

        void do_server()
        {
            app().loadConfigFile("./config.json").run();
        }
        std::thread httpServerThread(do_server); 
        httpServerThread.detach();
MiQter commented 1 month ago

How to notify the drogon app(). run() function in a child thread to close? 如何通知子线程里drogon的app().run()函数关闭?

an-tao commented 1 month ago

app().quit()