Problem with io_context.run( )
Solved
General and Desktop
-
Hello everyone,
I want to write chat in Qt with boost library. I did it in past in terminal and it worked.
I want to start server in widget constructor:
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); boost::asio::io_context io_context; tcp::endpoint endpoint(tcp::v4(), 2000); chat_server server(io_context, endpoint); io_context.run(); }
Problem is with this io_context.run(). There is no error, program compiles and runs, but application window doesn't appear. I do sth wrong here. Maybe constructor is a wrong place to start server? Maybe I have to start after click some button? Or maybe sth else? Please help.
-
@Krrris88 said in Problem with io_context.run( ):
Maybe constructor is a wrong place to start server?
Yes, if run() is a blocking call you're blocking the event queue.
You should move this boost part in another thread.