Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with io_context.run( )

Problem with io_context.run( )

Scheduled Pinned Locked Moved Solved General and Desktop
boostasio
3 Posts 2 Posters 783 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krrris88
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • K Krrris88

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Krrris88
        wrote on last edited by
        #3

        Thanks for answer.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved