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. [SOLVED] How to prevent form from closing after clicking OK from msgbox
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to prevent form from closing after clicking OK from msgbox

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.6k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sharon_obl82
    wrote on last edited by
    #1

    Hi,

    I have a form with a few line edit fields and one of them is mandatory. Upon clicking the Apply button, it will check if the mandatory field is filled in. If it's empty it will pop up a MsgBox like below:

    !http://i59.tinypic.com/kb2cmr.png(http://i59.tinypic.com/kb2cmr.png)!

    The thing is, I want the form to stay after Ok is clicked. Right now, the form disappears together with the msgbox when Ok is clicked. How do I prevent that to let user continue to stay on the form?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Please post the code of the slot that is called after you press "Apply".

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sharon_obl82
        wrote on last edited by
        #3

        Hi, my code is as below:

        @
        void rw::on_pushButton_clicked()
        {

        rinsert = new Radio;
        rinsert->SerialNumber = ui->lineEdit->text();
        
        if (formevent == "New") //assigned outside this function
        {
            if(rinsert->SerialNumber.isEmpty())
            {
                QMessageBox alert;
                alert.setWindowTitle("Error");
                alert.setText("Serial Number field is mandatory and must contain valid values");
                alert.exec();
            }else
            {
                //do something else
            }
        
        }
        
        //emit signal
        QString signal = "radio";
        emit radiosignal(signal);
        this->close();
        

        }
        @

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          What is the close call ? It is closing your window. Hope it is according to your logic.

          this->close();
          

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            As Dheerendra said, you are explicitly calling close(), so it is not surprising the window is closed.

            Also, I suggest renaming the "signal" QString: this word is a macro defined by Qt, it might cause troubles.

            (Z(:^

            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