我试图创建一个必须在启动时隐藏的小工具,所以我正在做:
w.showMinimized();
w.hide();
在main.cpp上的以隐藏模式调用我的MainWindow,但问题是当我调用FinishSession()这是从MainWindow of Course调用的ProductDlg类函数时,每当我点击“是”时它就存在或者没有“你看到QMessageBox吼叫
void ProductsDlg::FinishSession()
{
if(Session)
{
if(this->isActiveWindow())
{
this->hide();
}
QMessageBox::StandardButton _finishSession = QMessageBox::question(this , "Question" , "Do you wanna Finish the Session ?" , QMessageBox::Yes | QMessageBox::No); // THIS MESSAGEBOX - IT EXISTS AFTER THIS
if(_finishSession == QMessageBox::Yes)
{
Session = false;
}
}
else
{
qDebug() << "No Session is Running";
}
}
这是来自MainWindow.cpp,我称之为ProductsDlg:
bool MainWindow::nativeEvent(const QByteArray &eventType , void *message , long *result)
{
Q_UNUSED(eventType);
Q_UNUSED(result);
MSG * msg = static_cast<MSG*>(message);
if(msg->message == WM_HOTKEY)
{
if(msg->wParam == 0)
{
if(!pd->isVisible())
{
QRect rect = QApplication::desktop()->availableGeometry();
pd->show();
pd->setFocus();
pd->activateWindow();
pd->move(rect.width() - pd->width() , rect.height());
QPropertyAnimation *ani = new QPropertyAnimation(pd , "pos");
ani->setDuration(700);
ani->setStartValue(pd->pos());
ani->setEndValue(QPoint(rect.width() - pd->width() , rect.height() - pd->height()));
ani->start();
}
else if(!pd->isActiveWindow())
{
pd->activateWindow();
}
else if(pd->isActiveWindow())
{
pd->hide();
}
}
else if(msg->wParam == 1)
{
pd->FinishSession();
}
else if(msg->wParam == 2)
{
if(pd->isActiveWindow())
{
pd->hide();
}
}
else
{
return false;
}
}
else
{
return false;
}
}
'pd'是全局定义的,并在MainWindow构造函数上初始化。
答案 0 :(得分:1)
在这里找到答案:
Qt 5.1 - QMessageBox Bug? Program Exits(0) if QMessageBox is called while QDialog is hidden
我向main.cpp添加了qApp->setQuitOnLastWindowClosed(false);
,问题解决了!