accept operation fail in release mode
-
hi,I use accept to close a QWIDGET. It works well in debug mode,but in release mode ,it will not disappear
-
@yangyanhui4
This is nowhere near enough of a description. Supply a minimal reproducible example --- not just huge code! --- if you want someone to look at it. -
class MessageReminder : public QDialog
{
Q_OBJECTpublic:
explicit MessageReminder(QString text, int duration,QWidget* parent = 0);
~MessageReminder();
protected:
// 双击关闭窗口
void mouseDoubleClickEvent(QMouseEvent* event);
private slots:
void onTimeupDestroy();
private:
Ui::MessageReminder* ui;QTimer* remainTimer;
};
MessageReminder::MessageReminder(QString text, int duration, QWidget* parent) :
QDialog(parent),
ui(new Ui::MessageReminder)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint
| Qt::Tool
| Qt::WindowStaysOnTopHint);
//设置属性:关闭即销毁
this->setAttribute(Qt::WA_DeleteOnClose);
//让QLabel自适应text的大小
ui->label->adjustSize();
//让QLabel能够自动判断并换行显示:
//ui->label->setGeometry(QRect(328, 240, 329, 27 * 4)); //四倍行距
ui->label->setWordWrap(true);
//ui->label->setAlignment(Qt::AlignTop);
//text为要显示的信息
ui->label->setText(text);
ui->horizontalLayout->setSizeConstraint(QLayout::SetFixedSize);
//设置定时器,到时关闭弹框
remainTimer = new QTimer(this);
remainTimer->start(duration * 1000);
remainTimer->setSingleShot(true);//仅触发一次
connect(remainTimer, SIGNAL(timeout()), this, SLOT(onTimeupDestroy()));
}MessageReminder::~MessageReminder()
{
delete ui;
delete remainTimer;
}void MessageReminder::onTimeupDestroy() {
//this->close();
this->accept();
}
void MessageReminder::mouseDoubleClickEvent(QMouseEvent* event)
{
onTimeupDestroy();
}this is core code, I use this->accept to close the window,but it makes no sense in release mode
-
@yangyanhui4
But why do you attempt to usethis->accept()
here? That is for using in an override ofcloseEvent()
. You do not have such an overridden method. You have a slotonTimeupDestroy()
, which is called either from a timer signal or from a mouse double click event. Show me where the docs state anything about usingQWidget::accept()
from either of these?Your commented-out
this->close();
looks closer to what you should have. -
@JonB said in accept operation fail in release mode:
QWidget::accept()
QDialog::accept() technically exists :)