Qt模态对话框和主进程 [英] Qt modal dialog and main process

查看:30
本文介绍了Qt模态对话框和主进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序在主窗口中执行一些进程,我需要一个带有一些自定义元素的模态对话框来显示进度.它还必须阻止用户与主窗口的交互.显示对话框时应运行主进程.为此目的,哪种方式更好(在 qt 中)?

I have a program which executes some process in main window and I need a modal dialog with some custom elements to be shown over it to show the progress. It also must block user interaction with main window. Main process should run while dialog is shown. Which way is better (in qt) for this purpose?

推荐答案

其实这听起来很简单(除非我误解了你的问题).

Actually, this sounds kinda easy (unless I misunderstand your question).

QDialog my_progress_dialog( this );
my_progress_dialog.setModal( true );
my_progress_dialog.show();

调用 show() 而不是 exec() 将使您留在主事件循环中.同时,设置对话框模式会阻止所有用户输入到主窗口.任务完成.

Calling show() not exec() will leave you in the main eventloop. At the same time, setting the dialog modal blocks all user input to the main window. Job done.

你看过QProgressDialog吗?正是为了这个目的.

Have you looked at QProgressDialog? It's there for exactly this purpose.

这篇关于Qt模态对话框和主进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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