基于QObject的类与其自身具有排队连接 [英] QObject based class has a queued connection to itself

查看:96
本文介绍了基于QObject的类与其自身具有排队连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一些正在处理的源代码.我发现有人编码的奇怪说法.源代码是具有QML GUI的GUI应用程序,并使用QT 4.7.x.

I was digging into some source code I am working on. I found a peculiar statement that someone had coded. The source code is a GUI application with a QML GUI and uses QT 4.7.x.

下面的代码段属于核心应用程序逻辑.

The snippet below belongs to core application logic.

// connect signal-slots for decoupling
QObject::connect (this, SIGNAL(setCurrentTaskSignal(int)), this, 
    SLOT(SetCurrentTaskSlot(int)), Qt::QueuedConnection);

奇怪的是,该对象通过排队连接连接到自身,这实际上意味着该对象可以同时驻留"在不同的线程中吗?

It's strange that the object connects to itself via a queued connection which essentially means that the object may "live" in different threads at the same time?

乍看之下,这对我来说毫无意义.任何人都可以考虑任何理由说明为什么这样的连接是合理的或需要的吗?这甚至行得通吗?

At first glance It didn't made any sense to me. Can anyone think of any reason why such a connection would be plausible or needed?. Would this even work?

推荐答案

它将正常工作.也许在调用SetCurrentTaskSlot之前需要一些事件循环处理吗?

It will work without any problem. Maybe there was some event loop processing required before calling SetCurrentTaskSlot?

请注意,QueuedConnection并不意味着某些对象位于不同的线程中. QueuedConnection意味着仅当发出信号时,才会直接调用相应的插槽.它将在事件循环中排队,并在将控制权交还给事件循环时进行处理

Note that QueuedConnection doesn't mean that something is in different thread. QueuedConnection means only that when signal is emitted, corresponding slot won't be called directly. It will be queued on event loop, and will be processed when control will be given back to event loop

这篇关于基于QObject的类与其自身具有排队连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆