English 中文(简体)
问题:在事件发生时是否有通知?
原标题:Qt: Is there notification when event loop starts?

我有这种主要(Qt)申请。

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    MainWindow   mainWin;

    ... A separate, non-GUI thread is launched here

    mainWin.Init();
    mainWin.show();

    app.exec();
}

这是在主线之前创造的另一种深层。 Win需要知道何时可以开始与主Win沟通。 但自从主妇使用以来 信号、位置、时间等,在事件发生之前,它没有真正准备好岩石(通过外部()。

我的问题是:在事件爆发时,是否有信号或事件?

考虑这一点。 在主Win.Init(Init)中,你可以创造像Qtimer这样的东西,甚至叫.......开始()把它拉开。 但是,它实际上获得了胜利,在被召唤之前就触发事件。 因此,我需要知道事件发生的时间。

最佳回答

You can send a signal to your window before the exec() call. This will place an entry in app s signal queue. When exec() is running, the signal will be delivered and your window will know that the event loop is running.

使用<代码>Qtimer: Shot(0, &mainWin, SLOT(onEventLoopStarted()));,与你的窗口类别习惯位置连接。

问题回答

Since emitted signals don t get lost when the event loop is not yet running, your thread may not necessarily need to know when your window is ready.
Your thread could start sending signals to the window right away but it will only receive signals from the window when the event loop is running.

你可以按以下顺序这样做:

QApplication app(argc, argv);
Mainwinwdow mainWin;
QThread yourThread;

//connect the signals from the thread to the mainWin here

mainWin.Init();
mainWin.show();

yourThread.start();

return app.exec();




相关问题
Mysql trigger/events vs Cronjob

I have an auction website which let my users place an unlimited amount of autobiddings. To monitor these autobiddings something has to check the database every second. My question is if it is ...

Can an event be used as an event listener?

I m trying to expose some events from a private object which is contained inside the object I am creating and it looks like the compiler is happy with this: private WindowUpdateServer ...

鸡奸

由于将javascript DOM方法放在第html页底部(在<有人>之后)远比利用“j Query”准备活动要快得多,因此我们不得不这样做:

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

jQuery bind on ajax load() event

I have a page which displays multiple blocks with results details. Inside each block I have some <a> tags with thickbox jQuery plugin attached: class="thickbox" Here is an example of one kind ...

HTML text input event

I have a form, and want to disable/enable its submit button depending on whether the form s input text fields are empty or have had text entered into them. I think this means having an event handler ...

IE doesn t run Javascript when you click back button

I ve built a shop with tons of JS running. One of the pieces of the cart, is a zip code field which is required to calculate shipping cost. This works fine going through the cart. Now clicking ...

热门标签