title: How can i make a two message events for json Data by pushButton click in Qt?
body: <p>How can I make a message?</p>
  
  <p>I want make 2 message events. First, if is nothing include in my lineEdits and push the button. Must come error message "You have not includet the data". And second, if i include my lineEdits and push the button. Must come message "You have includet the data." But it's not work for me. If i push the button, then program saved empty json. If i push write data in lineEdits and push the button, then program saved as normal json. But no matter how I write, the programs always overwrite old json file. And I always get the logging that I have stored data.</p>
  
  <p>Here is my code:</p>
  
  <p>My .Cpp file:</p>
  
  <pre><code>#include "address_dialog.h"
  #include "ui_address_dialog.h"
  
  Address_Dialog::Address_Dialog(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::Address_Dialog)
  {
      ui-&gt;setupUi(this);
  
      connect(ui-&gt;pb_Cancel,SIGNAL(clicked(bool)),this,SLOT(close()));
      //Save data in json on click
      connect(ui-&gt;pb_save,SIGNAL(clicked(bool)),
      this,SLOT(on_pb_save_clicked()));
  }
  Address_Dialog::~Address_Dialog()
  {
      delete ui;
  }  
  
  void Address_Dialog::SaveDat()
  {
      m_address.mVorname= ui-&gt;le_Vorname-&gt;text();
      m_address.mNachname= ui-&gt;le_Nachname-&gt;text();
      m_address.mLand= ui-&gt;le_Land-&gt;text();
      m_address.mName= ui-&gt;le_Name-&gt;text();
      m_address.mPassword= ui-&gt;le_Password-&gt;text();
  
      QJsonObject json_obj;
  
      json_obj["FirstName"]= m_address.mVorname;
      json_obj["MiddleName"]= m_address.mNachname;
      json_obj["Country"]= m_address.mLand;
      json_obj["NickName"]= m_address.mName;
      json_obj["Password"]= m_address.mPassword;
  
      //Open the file for Recording using the path specified
      QString file_path = "C:/Users/frs/Documents/test_obj.json";
  
      QFile save_file(file_path);
      save_file.open(QIODevice::WriteOnly);
      //if(!save_file.open(QIODevice::WriteOnly))
          //QMessageBox::warning(0,"Error","Cannot open the file");
  
      QJsonDocument json_doc(json_obj);
      QString json_string = json_doc.toJson();
  
      if(save_file.write(json_string.toLocal8Bit()))
         QMessageBox::information(0,"Saving....",
              "The item has been successfully added");
      else
         QMessageBox::critical(0,"Error","The item cannot be added");
         save_file.close();
  }
  
  void Address_Dialog::on_pb_save_clicked()
  {
      SaveDat();
  }
  </code></pre>
  
  <p>That is my .H file</p>
  
  <pre><code>#ifndef ADDRESS_DIALOG_H
  #define ADDRESS_DIALOG_H
  
  #include &lt;QDialog&gt;
  #include &lt;QMessageBox&gt;
  #include "address.h"
  #include &lt;QFile&gt;
  #include &lt;QJsonObject&gt;
  #include &lt;QJsonArray&gt;
  #include &lt;QJsonDocument&gt;
  #include &lt;QString&gt;
  #include &lt;QDir&gt;
  
  namespace Ui
  {
      class Address_Dialog;
  }
  
  class Address_Dialog : public QDialog
  {
      Q_OBJECT
  
  public:
      explicit Address_Dialog(QWidget *parent = 0);
      ~Address_Dialog();
  
      Address m_address;//Creation of the Class object &lt;=&gt; /*QString mVorname, 
        // mNachname, mLand, mName, mPassword;*/
  
  private slots:
      void on_pb_save_clicked();
      void SaveDat();
  
  private:
      Ui::Address_Dialog *ui;
  
  };
  
  #endif // ADDRESS_DIALOG_H
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/TjyRU.jpg" alt="enter image description here"></p>