QT 几个异步模式对话框
在我的程序中,有一个循环,其中有类似的内容:
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(path)));
该函数被调用多次。在“回复完成”时,程序显示模式对话框(例如,常规 QDialog)。问题是我希望对话一个接一个地出现,而不是像现在这样同时出现。
我尝试对每个“等待”对话框使用
QList<QEventLoop *> stack;
一个 QEventLoop。但在我看来,这是一个糟糕的解决方案。
In my program there is a cycle in which there is something like that:
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(path)));
This function is called several times. On "reply finished" the program displays modal dialog (for example, regular QDialog). The problem is that I want dialogues to appear one after another, rather than all at once, together, as it happened now.
I tried to use
QList<QEventLoop *> stack;
One QEventLoop for every "waiting" dialog. But it seems to me that this is bad solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要使用
QEventLoop
。如果对话框是模式对话框,那么它会阻止所有其他对话框获取输入。在这种情况下,您应该在对话框关闭时发送信号。例如,您可以使用
QDialog::Finished(int)
。信号接收者正是打开对话框的对象。您可以为第一条消息自行调用此方法。
如果对话框是非模态的,那么您需要使用单次
QTimer
来延迟下一个对话框。基本上,每次显示对话框时,您都会计算希望显示另一个对话框的最早时间,并根据该时间设置一个计时器。当它被触发时,您检查消息并打开对话框,依此类推...
但是我想知道对话框是否是显示连续输入信息的最佳方式。
You don't need to use
QEventLoop
.If the dialog is modal, then it prevent all others to get input. In this case you should send a signal when the dialog is closed. You can use
QDialog::Finished(int)
for example. The signal receiver is non other than the object which opened the dialog.And you can call this method yourself for the first message.
If the dialog is non modal, then you need to use singleshot
QTimer
to delays next dialog.Basically each time you display a dialog, you compute the earliest time you want another dialog to be shown and you set up a timer with this time. When it is fired, you check for a message and open a dialog, and so on...
However I wonder if dialogs are the best way to show continuous input of information.