<small id='vulLQ'></small><noframes id='vulLQ'>

  1. <tfoot id='vulLQ'></tfoot>
    <legend id='vulLQ'><style id='vulLQ'><dir id='vulLQ'><q id='vulLQ'></q></dir></style></legend>
    • <bdo id='vulLQ'></bdo><ul id='vulLQ'></ul>

    1. <i id='vulLQ'><tr id='vulLQ'><dt id='vulLQ'><q id='vulLQ'><span id='vulLQ'><b id='vulLQ'><form id='vulLQ'><ins id='vulLQ'></ins><ul id='vulLQ'></ul><sub id='vulLQ'></sub></form><legend id='vulLQ'></legend><bdo id='vulLQ'><pre id='vulLQ'><center id='vulLQ'></center></pre></bdo></b><th id='vulLQ'></th></span></q></dt></tr></i><div id='vulLQ'><tfoot id='vulLQ'></tfoot><dl id='vulLQ'><fieldset id='vulLQ'></fieldset></dl></div>

    2. 如何在 BOOST 中在一个线程中发送信号并在另一个线程中执行相应的插槽?

      时间:2023-07-20
            <tfoot id='mrS48'></tfoot>

            1. <legend id='mrS48'><style id='mrS48'><dir id='mrS48'><q id='mrS48'></q></dir></style></legend>
                <tbody id='mrS48'></tbody>

              <small id='mrS48'></small><noframes id='mrS48'>

                <bdo id='mrS48'></bdo><ul id='mrS48'></ul>
                <i id='mrS48'><tr id='mrS48'><dt id='mrS48'><q id='mrS48'><span id='mrS48'><b id='mrS48'><form id='mrS48'><ins id='mrS48'></ins><ul id='mrS48'></ul><sub id='mrS48'></sub></form><legend id='mrS48'></legend><bdo id='mrS48'><pre id='mrS48'><center id='mrS48'></center></pre></bdo></b><th id='mrS48'></th></span></q></dt></tr></i><div id='mrS48'><tfoot id='mrS48'></tfoot><dl id='mrS48'><fieldset id='mrS48'></fieldset></dl></div>
              • 本文介绍了如何在 BOOST 中在一个线程中发送信号并在另一个线程中执行相应的插槽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                例如,在 Qt 中,如果您在 GUI 线程以外的线程中发出信号,则该信号会被排入队列并稍后在 GUI 线程中执行,有没有办法通过 boost 来做到这一点?

                In Qt for instance if you emit a signal in a thread other that the GUI thread, the signal is enqueued and executed later in the GUI thread, is there a way to do that with boost?

                谢谢

                推荐答案

                对于事件循环,请使用 boost::asio::io_service.您可以在此对象中发布任务并让另一个线程以线程安全的方式执行它们:

                For an event loop use boost::asio::io_service. You can post tasks inside this object and have another thread execute them, in a thread safe way:

                struct MyClass
                {
                    boost::io_service service;
                    void doSomethingOp() const { ... }
                
                    void doSomething()
                    {
                        service.post(boost::bind(&MyClass::doSomethingOp, this));
                    }
                
                    void loop()
                    {
                            service.run(); // processes the tasks
                    }
                };
                
                boost::signal<void()> mySignal;
                
                MyClass myClass;
                mySignal.connect(boost::bind(&MyClass::doSomething, boost::ref(myClass)));
                
                // launches a thread and executes myClass.loop() there
                boost::thread t(boost::bind(&MyClass::loop(), boost::ref(myClass)));
                
                // calls myClass.doSomething() in this thread, but loop() executes it in the other
                mySignal(); 
                

                这篇关于如何在 BOOST 中在一个线程中发送信号并在另一个线程中执行相应的插槽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:static_cast 和 Implicit_cast 有什么区别? 下一篇:如何将 boost::posix_time::ptime 转换为 time_t?

                相关文章

                • <bdo id='7dc4f'></bdo><ul id='7dc4f'></ul>

                    <tfoot id='7dc4f'></tfoot>
                    <i id='7dc4f'><tr id='7dc4f'><dt id='7dc4f'><q id='7dc4f'><span id='7dc4f'><b id='7dc4f'><form id='7dc4f'><ins id='7dc4f'></ins><ul id='7dc4f'></ul><sub id='7dc4f'></sub></form><legend id='7dc4f'></legend><bdo id='7dc4f'><pre id='7dc4f'><center id='7dc4f'></center></pre></bdo></b><th id='7dc4f'></th></span></q></dt></tr></i><div id='7dc4f'><tfoot id='7dc4f'></tfoot><dl id='7dc4f'><fieldset id='7dc4f'></fieldset></dl></div>

                    <small id='7dc4f'></small><noframes id='7dc4f'>

                  1. <legend id='7dc4f'><style id='7dc4f'><dir id='7dc4f'><q id='7dc4f'></q></dir></style></legend>