Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. accept operation fail in release mode
Forum Updated to NodeBB v4.3 + New Features

accept operation fail in release mode

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 484 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yangyanhui4
    wrote on last edited by
    #1

    hi,I use accept to close a QWIDGET. It works well in debug mode,but in release mode ,it will not disappear

    JonBJ 1 Reply Last reply
    0
    • Y yangyanhui4

      hi,I use accept to close a QWIDGET. It works well in debug mode,but in release mode ,it will not disappear

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yangyanhui4
        wrote on last edited by
        #3

        class MessageReminder : public QDialog
        {
        Q_OBJECT

        public:
        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

        JonBJ 1 Reply Last reply
        0
        • Y yangyanhui4

          class MessageReminder : public QDialog
          {
          Q_OBJECT

          public:
          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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @yangyanhui4
          But why do you attempt to use this->accept() here? That is for using in an override of closeEvent(). You do not have such an overridden method. You have a slot onTimeupDestroy(), which is called either from a timer signal or from a mouse double click event. Show me where the docs state anything about using QWidget::accept() from either of these?

          Your commented-out this->close(); looks closer to what you should have.

          J.HilkJ 1 Reply Last reply
          0
          • JonBJ JonB

            @yangyanhui4
            But why do you attempt to use this->accept() here? That is for using in an override of closeEvent(). You do not have such an overridden method. You have a slot onTimeupDestroy(), which is called either from a timer signal or from a mouse double click event. Show me where the docs state anything about using QWidget::accept() from either of these?

            Your commented-out this->close(); looks closer to what you should have.

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @JonB said in accept operation fail in release mode:

            QWidget::accept()

            QDialog::accept() technically exists :)


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            JonBJ 1 Reply Last reply
            1
            • J.HilkJ J.Hilk

              @JonB said in accept operation fail in release mode:

              QWidget::accept()

              QDialog::accept() technically exists :)

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @J-Hilk
              OK, I didn't notice OP was using QDialog rather than QWidget. The OP's question read:

              I use accept to close a QWIDGET

              @yangyanhui4
              How are you invoking this MessageReminder then? Are you calling QDialog::exec()?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved