我有QMessageBox作为widget类的成员 如果我们关闭小部件消息框未关闭,则消息框保持打开并通过程序。我也为消息框
做了setParent// Code local to a function
reply = m_warningMsg.question(this,"Warning","Do you really want to close the connection",QMessageBox::Yes | QMessageBox::No);
if(reply == QMessageBox::No)
{
return;
}
//Function to close the widget
void Window::closeConnection()
{
m_warningMsg.setParent(this);
m_warningMsg.setVisible(true);
// Code inside if executed but not hiding messagebox
if(m_warningMsg.isVisible())
{
m_warningMsg.close();
m_warningMsg.hide();
}
close();
}
答案 0 :(得分:2)
QMessageBox::question()
是一种静态方法,因此m_warningMsg
不是显示的QMessageBox
,因为您作为父参数作为参数传递给我们,我们可以找到{{1} (请注意,没有必要使用findchild()
:
QMessageBox
)
m_warningMsg
QMessageBox::StandardButton reply = QMessageBox::question(this,"Warning","Do you really want to close the connection",QMessageBox::Yes | QMessageBox::No);
if(reply == QMessageBox::No)
{
return;
}