English 中文(简体)
我能用什么来取代睡觉和睡觉。
原标题:what can I use to replace sleep and usleep in my Qt app?

我把现行法典的一部分进口到我方的 app中,并注意到那里有睡觉功能。 我认为,这种职能在拟定方案时没有位置。 我应该做些什么?

UPDATE:经过深思熟虑和反馈,我要说的是:只有在德国马克主线外睡觉,而且如果你需要等到德国马克的校对使用程序,否则,德国金融情报中心将无法冻结。

最佳回答

没有必要彻底打破这些事件。 我需要做的是打上<代码>QApplication:processEvents(>,其中sleep(>,并因此防止了GUI冻结。

问题回答

I don t recommend sleep in a event based system but if you want to ...
You can use a waitcondition, that way you can always interrupt the sleep if neccesary.

//...
QMutex dummy;
dummy.lock();
QWaitCondition waitCondition;
waitCondition.wait(&dummy, waitTime);
//...

造成睡觉的原因是,在根据方案进行规划时,由于基于事件的方案规划实际上是一种非预防性的多重任务的形式。 通过叫睡觉,你防止了任何其他事件的发生,从而阻碍read子的处理。

在申请函授中,发送了申请,立即等待答复。 Qt有好的标书,将确保在等待活动时,记本不会受阻。 活动将到来。 在你的案件中,QSocket:Rereadady信号是你的朋友。

如果你希望今后某个时间安排一次活动,则使用时间。 这将确保不阻止其他事件。

我不知道QTs如何在内部处理事件,但在大多数最低层次的系统中,应用寿命也一样:主要校对代码基本上是一种 lo(message loop),在每一处,申请都要求有赋予它的新信息的功能;这种功能通常受阻,也就是说,如果没有电文,功能不会返回,申请就会停止。

每当职能回报时,申请都有一个新的处理信息,通常有某些接收人(发送的窗口),意思是(电码,例如移动点)和一些补充数据(例如,变体已移至至24、12<>)。

现在,申请必须处理这一信息;本组织或全球倡议工具包通常在顶端这样做,因此,某些黑魔把信息发送到接收方,而正确的事件手被执行。 当活动投递人返回时,称为活动投递人返回的内部功能,也即叫人返回的内部功能,在控制回到主要圈子之前,这种功能现在将再次称为魔鬼信息传播功能,以获取另一个信息。 这一周期持续到申请终止。

现在,我写了所有这一切,使你明白为什么在一项由全球倡议驱动的活动中睡觉不好:如果你注意到,虽然电文已经处理,但其他电文不能处理<>,因为主线是忙于管理你的活动手,但毕竟只是电文传要求的一种功能。 因此,如果你睡觉,电文 lo也会睡觉,这意味着申请同时赢得收音,并处理任何其他信息,包括使你的窗户重新铺门的电文,因此,你的申请将从用户的角度来看待“hang”。

长期短故事:除非你不得不在很短的时间内睡觉(在大多数时间上超过数百毫秒),否则全球倡议会变得不敏感。 您有若干选择可以取代sleep:你可以使用一个时间(时间),但可以要求你在时间活动之间做许多簿记。 一种受欢迎的选择是开始单独的工人读物:它只是处理民盟的通信,并且与主线分开,它不会在必要时造成任何睡觉的问题。 显然,你必须注意保护read子之间共享的数据,并小心避免种族状况和充满多面的所有其他问题。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?