Qt QMainWindow独立

Qt QMainWindow独立,qt,qmainwindow,Qt,Qmainwindow,我有两扇窗户。我希望当QMainWindow上显示一个带有exec()的QMessageBox时,另一个QMainWindow不会被阻止 两个QMainWindow必须是独立的 如何操作?使用show()方法来显示每个QMainWindow,而不是exec() 它与QThread无关,Qt文档说明一个Qt应用程序中只能有一个GUI线程 您应该做的是设置模态标志以使对话框成为模态,这样它将与其父窗口相关。在执行对话框之前,请调用: pDialog->setWindowModality( Qt

我有两扇窗户。我希望当QMainWindow上显示一个带有exec()的QMessageBox时,另一个QMainWindow不会被阻止

两个QMainWindow必须是独立的


如何操作?

使用
show()
方法来显示每个
QMainWindow
,而不是
exec()

它与QThread无关,Qt文档说明一个Qt应用程序中只能有一个GUI线程

您应该做的是设置模态标志以使对话框成为模态,这样它将与其父窗口相关。在执行对话框之前,请调用:

pDialog->setWindowModality( Qt::WindowModal );
不要忘记为对话框对象设置一个适当的父对象

Qt文件说明:-

Modal Dialogs

A modal dialog is a dialog that blocks input to other visible windows in the 
same application. Dialogs that are used to request a file name from the user or 
that are used to set application preferences are usually modal. Dialogs can be 
application modal (the default) or window modal.

这与
QThread
有什么关系?目前还没有什么。但是我认为QmainWindows必须是独立的,就像它们是QThreads一样。QmainWindows是用show显示的。我需要使用exec for QMessageBox来处理结果。