Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Refresh QLCDNumber
Qt 6.11 is out! See what's new in the release blog

Refresh QLCDNumber

Scheduled Pinned Locked Moved Solved General and Desktop
36 Posts 3 Posters 23.2k Views 3 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.
  • martial123M martial123

    @mrjj

    You are right ...
    I created a new instance but never show him with instance.show()
    because the window is already open and the instance has already been created ... so I should get this instance and call the connect on it. but how to do that?

    my window are open like this before push to connect slot display() :

    #include "window018703.h"
    #include "ui_window018703.h"
    #include <iostream>
    
    //#define  B 1
    using namespace std;
    Window018703::Window018703(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Window018703)
    {
        ui->setupUi(this);
        //int a =5;
        cout << " nous somme avant l'appuis " <<  endl;
    
        QObject::connect(ui->pushButton, &QPushButton::clicked, this, &Window018703::set_lcdNumber_seatUp);
        cout << " nous somme apres l'appuis " <<  endl;
    
    }
    
    Window018703::~Window018703()
    {
        delete ui;
    }
    
    void Window018703::windowView()
    
    {
        this->show();
    }
    
    void Window018703::set_lcdNumber_seatUp()
    {
        static int B = 0;
        cout << " önt rentre ici et a vaut = " << B << endl;
        ui->lcdNumber_seatUp->display(B++);
    }
    

    i think in windows018704 class , I have to recover this instance? :

    
    void Window018703::windowView()
    
    {
        this->show();
    }
    

    this is a slot who call by an other class when users are finished to fill in all entries...

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #6

    Hi
    But where do you create the first instance?
    Could you not connect it to the other window there?

    martial123M 1 Reply Last reply
    1
    • mrjjM mrjj

      Hi
      But where do you create the first instance?
      Could you not connect it to the other window there?

      martial123M Offline
      martial123M Offline
      martial123
      wrote on last edited by
      #7

      @mrjj

      in fact, my program are composed by 3 classe :

      • a graphical class is used by users to fill fields
        when all fieds are filled,
        this class sets off this slot with this connect :
              if(this->get_m_boxGGI() == 18703)
              {
                  Window018703 *window018703 = new Window018703();
                  QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);
      
              }
      

      the slot :

      void Window018703::windowView()
      
      {
          this->show();
      }
      

      so after that, first class is hide() and the second class is show with this->show.
      then, the third class countain juste 1 button ( for example,
      because later it's a reception on the serial port that will declancher the incrementation of the QLCDNumber) to connect with slot who increment display ...

      so the second window is already open , so i need to recover the first instance that served to show him but i don't know how ...

      if i do that :

      void Window018703::set_lcdNumber_seatUp()
      {
          static int B = 0;
          cout << " önt rentre ici et a vaut = " << B << endl;
          this->show();
          ui->lcdNumber_seatUp->display(B++);
      }
      

      Window018703 redisplay and after that , it work ..
      but normally, window are already open so that's not quite what I want

      it is clearer ?
      Thanks a lot ...

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #8

        Hi
        So is
        if(this->get_m_boxGGI() == 18703)
        {
        Window018703 *window018703 = new Window018703(); << the real instance ?
        QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);

            }
        

        the only one ?
        also then its the THIRD class that needs to talk to Window018703 ?

        martial123M 1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          So is
          if(this->get_m_boxGGI() == 18703)
          {
          Window018703 *window018703 = new Window018703(); << the real instance ?
          QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);

              }
          

          the only one ?
          also then its the THIRD class that needs to talk to Window018703 ?

          martial123M Offline
          martial123M Offline
          martial123
          wrote on last edited by
          #9

          @mrjj

          unless I'm wrong but yes it's the first instance
          and

          yes the third class talk to increment display ...

          the first class is hide because it just serves in start to fill variables especially : m_boxGGI ...

          mrjjM 1 Reply Last reply
          0
          • martial123M martial123

            @mrjj

            unless I'm wrong but yes it's the first instance
            and

            yes the third class talk to increment display ...

            the first class is hide because it just serves in start to fill variables especially : m_boxGGI ...

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #10

            Hi
            ok.
            Where is the code ?
            if(this->get_m_boxGGI() == 18703)
            {...
            is that in first window ?
            So if you store
            Window018703 *window018703 as a member, you can use it later to connect
            when you open the third one?

            martial123M 1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              ok.
              Where is the code ?
              if(this->get_m_boxGGI() == 18703)
              {...
              is that in first window ?
              So if you store
              Window018703 *window018703 as a member, you can use it later to connect
              when you open the third one?

              martial123M Offline
              martial123M Offline
              martial123
              wrote on last edited by
              #11

              @mrjj yes the code is in the first class ( first window)

              how i can store in in membre ??

              mrjjM 1 Reply Last reply
              0
              • martial123M martial123

                @mrjj yes the code is in the first class ( first window)

                how i can store in in membre ??

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #12

                @martial123
                and from first window, you also open the third one ? correct?
                To make it memeber.
                simply put
                Window018703 *window018703 = nullptr; in first window.h inside class
                like

                class MainWindow : public QMainWindow
                {
                    Q_OBJECT
                ......
                private:
                    Ui::MainWindow *ui;
                  Window018703 *window018703 = nullptr;  // also include the #include "Window018703.H" in top of file
                };
                
                

                and then change code here

                if(this->get_m_boxGGI() == 18703)
                {
                window018703 = new Window018703(); << use the one from .h
                QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);

                Then later the variable in .h (window018703 ) points to the instance.

                martial123M 1 Reply Last reply
                0
                • mrjjM mrjj

                  @martial123
                  and from first window, you also open the third one ? correct?
                  To make it memeber.
                  simply put
                  Window018703 *window018703 = nullptr; in first window.h inside class
                  like

                  class MainWindow : public QMainWindow
                  {
                      Q_OBJECT
                  ......
                  private:
                      Ui::MainWindow *ui;
                    Window018703 *window018703 = nullptr;  // also include the #include "Window018703.H" in top of file
                  };
                  
                  

                  and then change code here

                  if(this->get_m_boxGGI() == 18703)
                  {
                  window018703 = new Window018703(); << use the one from .h
                  QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);

                  Then later the variable in .h (window018703 ) points to the instance.

                  martial123M Offline
                  martial123M Offline
                  martial123
                  wrote on last edited by
                  #13

                  @mrjj

                  in fact, it is the main who show the third window but its not importante,

                  i did what you told me , but i can not to catch my instance ( or member ...) like this with get methode to call him in the third classe :

                  in first window .cpp :

                  Window018703* get_window018703()
                  {
                      return window018703;
                      
                  }
                  

                  .h :

                          Window018703* get_window018703();
                  
                  

                  he tell me an error :
                  use of undeclared identifier 'window018703'

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    Hi
                    Well then maybe you can connect in main ?
                    You really need access to the instance and there is no magical way to get it.
                    So if main know all 3 windows, you can connect there ?

                    martial123M 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      Hi
                      Well then maybe you can connect in main ?
                      You really need access to the instance and there is no magical way to get it.
                      So if main know all 3 windows, you can connect there ?

                      martial123M Offline
                      martial123M Offline
                      martial123
                      wrote on last edited by
                      #15

                      @mrjj
                      the instance is created when i do that no ? :

                      if(this->get_m_boxGGI() == 18703)
                             {
                                 window018703 = new Window018703();
                      
                                 QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);
                      
                             }
                      
                      mrjjM 1 Reply Last reply
                      0
                      • martial123M martial123

                        @mrjj
                        the instance is created when i do that no ? :

                        if(this->get_m_boxGGI() == 18703)
                               {
                                   window018703 = new Window018703();
                        
                                   QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);
                        
                               }
                        
                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #16

                        @martial123
                        Yes but you need that window018703 variable in third form.
                        And third form is created in main ?

                        martial123M 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @martial123
                          Yes but you need that window018703 variable in third form.
                          And third form is created in main ?

                          martial123M Offline
                          martial123M Offline
                          martial123
                          wrote on last edited by
                          #17

                          @mrjj
                          yes my main show first and third window ... :

                          #include <QApplication>
                          #include <QtWidgets>
                          #include <QLabel>
                          
                          #include "window1.h"
                          #include "window018703.h"
                          #include "window018704.h"
                          
                          
                          using namespace std;
                          int main(int argc, char *argv[])
                          {
                              QApplication app(argc, argv);
                                 window1 window1;
                                 window1.show();
                          
                                 Window018704 window2;
                                 window2.show();
                            
                              return app.exec();
                          }
                          
                          mrjjM 1 Reply Last reply
                          0
                          • martial123M martial123

                            @mrjj
                            yes my main show first and third window ... :

                            #include <QApplication>
                            #include <QtWidgets>
                            #include <QLabel>
                            
                            #include "window1.h"
                            #include "window018703.h"
                            #include "window018704.h"
                            
                            
                            using namespace std;
                            int main(int argc, char *argv[])
                            {
                                QApplication app(argc, argv);
                                   window1 window1;
                                   window1.show();
                            
                                   Window018704 window2;
                                   window2.show();
                              
                                return app.exec();
                            }
                            
                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #18

                            @martial123

                            So connect it all up there?
                            Im getting a bit confused with the names, so not sure if 04 has 03 or reverse.

                            
                                 window1 window1;
                                 window1.show(); << this has window018703 ?
                            
                                 Window018704 window2;
                                 connect( window1.get_window018703(), xxxx )
                                   
                                   window2.show();
                              
                            
                            
                            martial123M 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @martial123

                              So connect it all up there?
                              Im getting a bit confused with the names, so not sure if 04 has 03 or reverse.

                              
                                   window1 window1;
                                   window1.show(); << this has window018703 ?
                              
                                   Window018704 window2;
                                   connect( window1.get_window018703(), xxxx )
                                     
                                     window2.show();
                                
                              
                              
                              martial123M Offline
                              martial123M Offline
                              martial123
                              wrote on last edited by
                              #19

                              @mrjj

                              No ^^

                              i have 3 classes :

                              first : window1
                              second: Window018703
                              third : Window018704 ...

                              mrjjM 1 Reply Last reply
                              0
                              • martial123M martial123

                                @mrjj

                                No ^^

                                i have 3 classes :

                                first : window1
                                second: Window018703
                                third : Window018704 ...

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #20

                                @martial123
                                well you need one place where you have the instance you want to connect.
                                I not sure where Window018703 comes to life, but cant you call the get_window018703()
                                on it from main to get the instance.
                                It must be in window1 or window2 ? (variables)

                                martial123M 1 Reply Last reply
                                0
                                • mrjjM mrjj

                                  @martial123
                                  well you need one place where you have the instance you want to connect.
                                  I not sure where Window018703 comes to life, but cant you call the get_window018703()
                                  on it from main to get the instance.
                                  It must be in window1 or window2 ? (variables)

                                  martial123M Offline
                                  martial123M Offline
                                  martial123
                                  wrote on last edited by
                                  #21

                                  @mrjj

                                  I do not understand much anymore..

                                  i have the first class (window1) wiche is call and show by main :

                                  window1.cpp :

                                  #include "window1.h"
                                  #include "ui_window1.h"
                                  #include <iostream>
                                  #include "window018703.h"
                                  #include "window018704.h"
                                  
                                  //Constructor
                                  window1::window1(QWidget *parent) :
                                      QDialog(parent),
                                      ui(new Ui::window1)
                                  {
                                      //lance la construction de la fenetre
                                      ui->setupUi(this);
                                      //Signal emis
                                      QObject::connect(ui->pushButtonCancel, &QPushButton::clicked, qApp, &QCoreApplication::quit);
                                      QObject::connect(ui->pushButtonOk, &QPushButton::clicked, this, &window1::processing);
                                  
                                  }
                                  
                                  //Destructor
                                  window1::~window1()
                                  {
                                      delete ui;
                                  }
                                  
                                  //Gestion des erreurs SLOT en fonction des signaux emis
                                  // Range le contenu des champ dans un objet de type QString
                                  //Si c'est champ sont vide, alors on emet une fenetre erreur
                                  //Sinon, on ferme la fenetre.
                                  //************* Maj : Au lieu de fermer la fenetre, elle doit emmetre un signal pour ouvrir la suivante.*************
                                  //done  : test if on device choose by user , open the right window device.
                                  void window1::processing()
                                  {
                                  
                                      QString contents_m_fieldJob = ui->fieldJob->text();
                                      QString contents_m_fieldLotNumber = ui->fieldLotNumber->text();
                                      QString contents_m_fieldLogFile = ui->fieldLogFile->text();
                                      QString contents_m_fieldOperator = ui->fieldOperator->text();
                                      QString contents_m_boxNumberDevice = ui->boxNumberDevice->text();
                                      //Window018703 *obj1 = new Window018703();
                                      if(contents_m_fieldJob.isEmpty() || contents_m_fieldLotNumber.isEmpty() ||
                                        contents_m_fieldLogFile.isEmpty() || contents_m_fieldOperator.isEmpty() || contents_m_boxNumberDevice.toInt()== 0)
                                      {
                                          QMessageBox::information(this, "ERROR Message", "ERROR: Fill in all entries");
                                      }
                                      else
                                      {        
                                          QObject::connect(ui->pushButtonOk, &QPushButton::clicked , this, &QWidget::hide);
                                          if(this->get_m_boxGGI() == 18703)
                                          {
                                              //Window018703 *window018703 = new Window018703();
                                              window018703 = new Window018703();
                                  
                                              QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);
                                     
                                  
                                  
                                          }
                                          else if(this->get_m_boxGGI() == 18704)
                                          {
                                              Window018704 *window018704 = new Window018704();
                                              QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018704, &Window018704::windowView);
                                  
                                          }
                                      }
                                  
                                  }
                                  
                                  
                                  /***********************************GET***********************************/
                                  // Permet de recuperer les
                                  // utile pour le fichier de rapport
                                  // numero device utile pour la configuration
                                  // nombre de device utile pour la conf
                                  int window1::get_m_fieldJob() const
                                  {
                                      QString contents_m_fieldJob = ui->fieldJob->text();
                                      return contents_m_fieldJob.toInt();
                                  }
                                  
                                  int window1::get_m_fieldLotNumber() const
                                  {
                                      QString contents_m_fieldLotNumber = ui->fieldLotNumber->text();
                                      return contents_m_fieldLotNumber.toInt();
                                  }
                                  int window1::get_m_fieldLogFile() const
                                  {
                                      QString contents_m_fieldLogFile = ui->fieldLogFile->text();
                                      return contents_m_fieldLogFile.toInt();
                                  }
                                  int window1::get_m_fieldOperator() const
                                  {
                                      QString contents_m_fieldOperator = ui->fieldOperator->text();
                                      return contents_m_fieldOperator.toInt();
                                  }
                                  int window1::get_m_boxNombreDevice() const
                                  {
                                      QString contents_m_boxNombreDevice = ui->boxNumberDevice->text();
                                      return contents_m_boxNombreDevice.toInt();
                                  }
                                  
                                  int window1::get_m_boxGGI() const
                                  {
                                      QString contents_m_boxGGI = ui->boxGGI->currentText();
                                      return contents_m_boxGGI.toInt();
                                  }
                                  
                                  Window018703* window1::get_window018703() const
                                  {
                                      return window018703;
                                  
                                  }
                                  /**************************************************************************/
                                  

                                  window1.h :

                                  #ifndef WINDOW1_H
                                  #define WINDOW1_H
                                  #include <QWidget>
                                  
                                  #include <QDialog>
                                  #include <QMessageBox>
                                  #include <iostream>
                                  #include <QApplication>
                                  #include "window018703.h"
                                  #include "window018704.h"
                                  
                                  
                                  namespace Ui {
                                  class window1;
                                  }
                                  
                                  class window1 : public QDialog
                                  {
                                      Q_OBJECT
                                  
                                      public:
                                          explicit window1(QWidget *parent = nullptr);
                                          ~window1();
                                  
                                          /*get*/
                                          int get_m_fieldJob() const;
                                          int get_m_fieldLotNumber() const;
                                          int get_m_fieldLogFile() const;
                                          int get_m_fieldOperator() const;
                                          int get_m_boxNombreDevice() const;
                                          int get_m_boxGGI() const;
                                  
                                          Window018703* get_window018703() const;
                                  
                                          /*set*/
                                  
                                      public slots:
                                          void processing();
                                  
                                      private:
                                          Ui::window1 *ui;
                                          Window018703 *window018703 = nullptr;
                                  };
                                  
                                  #endif // WINDOW1_H
                                  

                                  main.cpp :

                                  #include <QApplication>
                                  #include <QtWidgets>
                                  #include <QLabel>
                                  
                                  #include "window1.h"
                                  #include "window018703.h"
                                  #include "window018704.h"
                                  
                                  
                                  using namespace std;
                                  int main(int argc, char *argv[])
                                  {
                                      QApplication app(argc, argv);
                                         window1 window1;
                                         window1.show();
                                  
                                        Window018704 window3;
                                        window3.show();
                                         //ui->lcdNumber_seatUp->QLCDNumber();
                                         //qApp->setStyleSheet("Window018703 { background-color: dark }");
                                         //pour rendre le bouton de tyoe QPushButton non utilisable:
                                         //QPushButton *bouton = new QPushButton("bouton");
                                         //bouton->setEnabled(false)
                                      return app.exec();
                                  }
                                  

                                  at the start of program, this main show window 1 and window3 ( window018704)

                                  in the first class window1, we are a slot : void window1::processing()
                                  in this slot if users are fill in all input, then we call slot with this connect :

                                  window018703 = new Window018703();
                                  QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);

                                  this connect are receive by 2 class ( window018703) :
                                  Window018703.cpp :

                                  #include "window018703.h"
                                  #include "ui_window018703.h"
                                  #include <iostream>
                                  
                                  //#define  B 1
                                  using namespace std;
                                  Window018703::Window018703(QWidget *parent) :
                                      QDialog(parent),
                                      ui(new Ui::Window018703)
                                  {
                                      ui->setupUi(this);
                                      //int a =5;
                                      cout << " nous somme avant l'appuis " <<  endl;
                                  
                                      QObject::connect(ui->pushButton, &QPushButton::clicked, this, &Window018703::set_lcdNumber_seatUp);
                                      cout << " nous somme apres l'appuis " <<  endl;
                                  
                                  }
                                  
                                  Window018703::~Window018703()
                                  {
                                      delete ui;
                                  }
                                  
                                  void Window018703::windowView()
                                  
                                  {
                                      this->show();
                                  }
                                  
                                  void Window018703::set_lcdNumber_seatUp()
                                  {
                                      static int B = 0;
                                      cout << " önt rentre ici et a vaut = " << B << endl;
                                      //this->show();
                                      ui->lcdNumber_seatUp->display(B++);
                                  }
                                  

                                  slot void Window018703::windowView() is execute and the second window are show.

                                  so now , if i the connect in second class is execute ( QObject::connect(ui->pushButton, &QPushButton::clicked, this, &Window018703::set_lcdNumber_seatUp);)

                                  the display QLCDNumber is incremented because we are on the same instance (this)

                                  but if i connect with the third class ( Window018704) , it doesn't work .

                                  i have implemented the get but i can not :

                                  Window018704.cpp :

                                  #include "window018704.h"
                                  #include "ui_window018704.h"
                                  #include <iostream>
                                  #include "window1.h"
                                  
                                  
                                  using namespace std;
                                  
                                  Window018704::Window018704(QWidget *parent) :
                                      QDialog(parent),
                                      ui(new Ui::Window018704)
                                  {
                                      ui->setupUi(this);
                                      cout << " classe 704 ... " <<  endl;
                                  
                                     window1 *instance1 = new window1(); ;
                                      Window018703 *instance3 = new Window018703();
                                  
                                     instance3 = instance1->get_window018703();
                                  
                                     QObject::connect(ui->pushButton_018704, &QPushButton::clicked , instance3, &Window018703::set_lcdNumber_seatUp);
                                  
                                  }
                                  
                                  Window018704::~Window018704()
                                  {
                                      delete ui;
                                  }
                                  
                                  void Window018704::windowView()
                                  {
                                      this->show();
                                  
                                  }
                                  

                                  Window018704.h :

                                  #ifndef WINDOW018704_H
                                  #define WINDOW018704_H
                                  
                                  #include <QDialog>
                                  #include "window018703.h"
                                  #include <QApplication>
                                  #include <QObject>
                                  
                                  namespace Ui {
                                  class Window018704;
                                  }
                                  
                                  class Window018704 : public QDialog
                                  {
                                      Q_OBJECT
                                  
                                      public:
                                          explicit Window018704(QWidget *parent = nullptr);
                                          ~Window018704();
                                  
                                      public slots:
                                          void windowView();
                                  
                                  private slots:
                                          //void on_pushButton_018704_clicked();
                                  
                                  
                                  private:
                                          Ui::Window018704 *ui;
                                  };
                                  
                                  #endif // WINDOW018704_H
                                  

                                  i have understand what u tell me , but i can not receve the good instance from first class ( window018703 = new Window018703(); ) to connect the good instance in the third class :

                                  window1 *instance1 = new window1(); ;
                                  Window018703 *instance3 = new Window018703();

                                  instance3 = instance1->get_window018703();

                                  QObject::connect(ui->pushButton_018704, &QPushButton::clicked , instance3, &Window018703::set_lcdNumber_seatUp);

                                  Thank for your time ..

                                  mrjjM 1 Reply Last reply
                                  0
                                  • martial123M martial123

                                    @mrjj

                                    I do not understand much anymore..

                                    i have the first class (window1) wiche is call and show by main :

                                    window1.cpp :

                                    #include "window1.h"
                                    #include "ui_window1.h"
                                    #include <iostream>
                                    #include "window018703.h"
                                    #include "window018704.h"
                                    
                                    //Constructor
                                    window1::window1(QWidget *parent) :
                                        QDialog(parent),
                                        ui(new Ui::window1)
                                    {
                                        //lance la construction de la fenetre
                                        ui->setupUi(this);
                                        //Signal emis
                                        QObject::connect(ui->pushButtonCancel, &QPushButton::clicked, qApp, &QCoreApplication::quit);
                                        QObject::connect(ui->pushButtonOk, &QPushButton::clicked, this, &window1::processing);
                                    
                                    }
                                    
                                    //Destructor
                                    window1::~window1()
                                    {
                                        delete ui;
                                    }
                                    
                                    //Gestion des erreurs SLOT en fonction des signaux emis
                                    // Range le contenu des champ dans un objet de type QString
                                    //Si c'est champ sont vide, alors on emet une fenetre erreur
                                    //Sinon, on ferme la fenetre.
                                    //************* Maj : Au lieu de fermer la fenetre, elle doit emmetre un signal pour ouvrir la suivante.*************
                                    //done  : test if on device choose by user , open the right window device.
                                    void window1::processing()
                                    {
                                    
                                        QString contents_m_fieldJob = ui->fieldJob->text();
                                        QString contents_m_fieldLotNumber = ui->fieldLotNumber->text();
                                        QString contents_m_fieldLogFile = ui->fieldLogFile->text();
                                        QString contents_m_fieldOperator = ui->fieldOperator->text();
                                        QString contents_m_boxNumberDevice = ui->boxNumberDevice->text();
                                        //Window018703 *obj1 = new Window018703();
                                        if(contents_m_fieldJob.isEmpty() || contents_m_fieldLotNumber.isEmpty() ||
                                          contents_m_fieldLogFile.isEmpty() || contents_m_fieldOperator.isEmpty() || contents_m_boxNumberDevice.toInt()== 0)
                                        {
                                            QMessageBox::information(this, "ERROR Message", "ERROR: Fill in all entries");
                                        }
                                        else
                                        {        
                                            QObject::connect(ui->pushButtonOk, &QPushButton::clicked , this, &QWidget::hide);
                                            if(this->get_m_boxGGI() == 18703)
                                            {
                                                //Window018703 *window018703 = new Window018703();
                                                window018703 = new Window018703();
                                    
                                                QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);
                                       
                                    
                                    
                                            }
                                            else if(this->get_m_boxGGI() == 18704)
                                            {
                                                Window018704 *window018704 = new Window018704();
                                                QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018704, &Window018704::windowView);
                                    
                                            }
                                        }
                                    
                                    }
                                    
                                    
                                    /***********************************GET***********************************/
                                    // Permet de recuperer les
                                    // utile pour le fichier de rapport
                                    // numero device utile pour la configuration
                                    // nombre de device utile pour la conf
                                    int window1::get_m_fieldJob() const
                                    {
                                        QString contents_m_fieldJob = ui->fieldJob->text();
                                        return contents_m_fieldJob.toInt();
                                    }
                                    
                                    int window1::get_m_fieldLotNumber() const
                                    {
                                        QString contents_m_fieldLotNumber = ui->fieldLotNumber->text();
                                        return contents_m_fieldLotNumber.toInt();
                                    }
                                    int window1::get_m_fieldLogFile() const
                                    {
                                        QString contents_m_fieldLogFile = ui->fieldLogFile->text();
                                        return contents_m_fieldLogFile.toInt();
                                    }
                                    int window1::get_m_fieldOperator() const
                                    {
                                        QString contents_m_fieldOperator = ui->fieldOperator->text();
                                        return contents_m_fieldOperator.toInt();
                                    }
                                    int window1::get_m_boxNombreDevice() const
                                    {
                                        QString contents_m_boxNombreDevice = ui->boxNumberDevice->text();
                                        return contents_m_boxNombreDevice.toInt();
                                    }
                                    
                                    int window1::get_m_boxGGI() const
                                    {
                                        QString contents_m_boxGGI = ui->boxGGI->currentText();
                                        return contents_m_boxGGI.toInt();
                                    }
                                    
                                    Window018703* window1::get_window018703() const
                                    {
                                        return window018703;
                                    
                                    }
                                    /**************************************************************************/
                                    

                                    window1.h :

                                    #ifndef WINDOW1_H
                                    #define WINDOW1_H
                                    #include <QWidget>
                                    
                                    #include <QDialog>
                                    #include <QMessageBox>
                                    #include <iostream>
                                    #include <QApplication>
                                    #include "window018703.h"
                                    #include "window018704.h"
                                    
                                    
                                    namespace Ui {
                                    class window1;
                                    }
                                    
                                    class window1 : public QDialog
                                    {
                                        Q_OBJECT
                                    
                                        public:
                                            explicit window1(QWidget *parent = nullptr);
                                            ~window1();
                                    
                                            /*get*/
                                            int get_m_fieldJob() const;
                                            int get_m_fieldLotNumber() const;
                                            int get_m_fieldLogFile() const;
                                            int get_m_fieldOperator() const;
                                            int get_m_boxNombreDevice() const;
                                            int get_m_boxGGI() const;
                                    
                                            Window018703* get_window018703() const;
                                    
                                            /*set*/
                                    
                                        public slots:
                                            void processing();
                                    
                                        private:
                                            Ui::window1 *ui;
                                            Window018703 *window018703 = nullptr;
                                    };
                                    
                                    #endif // WINDOW1_H
                                    

                                    main.cpp :

                                    #include <QApplication>
                                    #include <QtWidgets>
                                    #include <QLabel>
                                    
                                    #include "window1.h"
                                    #include "window018703.h"
                                    #include "window018704.h"
                                    
                                    
                                    using namespace std;
                                    int main(int argc, char *argv[])
                                    {
                                        QApplication app(argc, argv);
                                           window1 window1;
                                           window1.show();
                                    
                                          Window018704 window3;
                                          window3.show();
                                           //ui->lcdNumber_seatUp->QLCDNumber();
                                           //qApp->setStyleSheet("Window018703 { background-color: dark }");
                                           //pour rendre le bouton de tyoe QPushButton non utilisable:
                                           //QPushButton *bouton = new QPushButton("bouton");
                                           //bouton->setEnabled(false)
                                        return app.exec();
                                    }
                                    

                                    at the start of program, this main show window 1 and window3 ( window018704)

                                    in the first class window1, we are a slot : void window1::processing()
                                    in this slot if users are fill in all input, then we call slot with this connect :

                                    window018703 = new Window018703();
                                    QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);

                                    this connect are receive by 2 class ( window018703) :
                                    Window018703.cpp :

                                    #include "window018703.h"
                                    #include "ui_window018703.h"
                                    #include <iostream>
                                    
                                    //#define  B 1
                                    using namespace std;
                                    Window018703::Window018703(QWidget *parent) :
                                        QDialog(parent),
                                        ui(new Ui::Window018703)
                                    {
                                        ui->setupUi(this);
                                        //int a =5;
                                        cout << " nous somme avant l'appuis " <<  endl;
                                    
                                        QObject::connect(ui->pushButton, &QPushButton::clicked, this, &Window018703::set_lcdNumber_seatUp);
                                        cout << " nous somme apres l'appuis " <<  endl;
                                    
                                    }
                                    
                                    Window018703::~Window018703()
                                    {
                                        delete ui;
                                    }
                                    
                                    void Window018703::windowView()
                                    
                                    {
                                        this->show();
                                    }
                                    
                                    void Window018703::set_lcdNumber_seatUp()
                                    {
                                        static int B = 0;
                                        cout << " önt rentre ici et a vaut = " << B << endl;
                                        //this->show();
                                        ui->lcdNumber_seatUp->display(B++);
                                    }
                                    

                                    slot void Window018703::windowView() is execute and the second window are show.

                                    so now , if i the connect in second class is execute ( QObject::connect(ui->pushButton, &QPushButton::clicked, this, &Window018703::set_lcdNumber_seatUp);)

                                    the display QLCDNumber is incremented because we are on the same instance (this)

                                    but if i connect with the third class ( Window018704) , it doesn't work .

                                    i have implemented the get but i can not :

                                    Window018704.cpp :

                                    #include "window018704.h"
                                    #include "ui_window018704.h"
                                    #include <iostream>
                                    #include "window1.h"
                                    
                                    
                                    using namespace std;
                                    
                                    Window018704::Window018704(QWidget *parent) :
                                        QDialog(parent),
                                        ui(new Ui::Window018704)
                                    {
                                        ui->setupUi(this);
                                        cout << " classe 704 ... " <<  endl;
                                    
                                       window1 *instance1 = new window1(); ;
                                        Window018703 *instance3 = new Window018703();
                                    
                                       instance3 = instance1->get_window018703();
                                    
                                       QObject::connect(ui->pushButton_018704, &QPushButton::clicked , instance3, &Window018703::set_lcdNumber_seatUp);
                                    
                                    }
                                    
                                    Window018704::~Window018704()
                                    {
                                        delete ui;
                                    }
                                    
                                    void Window018704::windowView()
                                    {
                                        this->show();
                                    
                                    }
                                    

                                    Window018704.h :

                                    #ifndef WINDOW018704_H
                                    #define WINDOW018704_H
                                    
                                    #include <QDialog>
                                    #include "window018703.h"
                                    #include <QApplication>
                                    #include <QObject>
                                    
                                    namespace Ui {
                                    class Window018704;
                                    }
                                    
                                    class Window018704 : public QDialog
                                    {
                                        Q_OBJECT
                                    
                                        public:
                                            explicit Window018704(QWidget *parent = nullptr);
                                            ~Window018704();
                                    
                                        public slots:
                                            void windowView();
                                    
                                    private slots:
                                            //void on_pushButton_018704_clicked();
                                    
                                    
                                    private:
                                            Ui::Window018704 *ui;
                                    };
                                    
                                    #endif // WINDOW018704_H
                                    

                                    i have understand what u tell me , but i can not receve the good instance from first class ( window018703 = new Window018703(); ) to connect the good instance in the third class :

                                    window1 *instance1 = new window1(); ;
                                    Window018703 *instance3 = new Window018703();

                                    instance3 = instance1->get_window018703();

                                    QObject::connect(ui->pushButton_018704, &QPushButton::clicked , instance3, &Window018703::set_lcdNumber_seatUp);

                                    Thank for your time ..

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by mrjj
                                    #22

                                    @martial123
                                    I fear, you make new ones on the go.

                                    window1 *instance1 = new window1(); ;

                                    is that not a new instance compared to the one in main.cpp?

                                    Please tell from main.cpp

                                       window1 window1;<< this has window018703 ?
                                       Window018704 window2; << this has window018703 ?
                                    

                                    we should be able to connect here.

                                    martial123M 1 Reply Last reply
                                    0
                                    • mrjjM mrjj

                                      @martial123
                                      I fear, you make new ones on the go.

                                      window1 *instance1 = new window1(); ;

                                      is that not a new instance compared to the one in main.cpp?

                                      Please tell from main.cpp

                                         window1 window1;<< this has window018703 ?
                                         Window018704 window2; << this has window018703 ?
                                      

                                      we should be able to connect here.

                                      martial123M Offline
                                      martial123M Offline
                                      martial123
                                      wrote on last edited by
                                      #23

                                      @mrjj

                                      Hi ,

                                      You don't understand,
                                      I have 3 graphic class:

                                      • Window 1
                                      • Window 018703
                                      • Window 018704

                                      so Window1 is not Window 018703 ...
                                      when i do that :

                                      window1 window1;
                                             window1.show();
                                      

                                      I created instance for the first class ( not by the second class 018703)
                                      If I would like to created the instance of Window018703 i do :

                                      Window018703 window2;
                                            window2.show();
                                      

                                      ok ?
                                      so the instance we want to recover is the instance Window018703 which is created in the slot in first class ( window1) like this ":

                                        if(this->get_m_boxGGI() == 18703)
                                              {
                                                 **window018703 = new Window018703();
                                      
                                                  QObject::connect(ui->pushButtonOk, &QPushButton::clicked , window018703, &Window018703::windowView);**
                                      }
                                      

                                      And we want to recover this instance(window018703) in the thrid class
                                      so to do that, with your advices, i have created the function get_window018703() in the first class , who able to return the only one instance like this :

                                      Window018703* window1::get_window018703() const
                                      {
                                          return window018703;
                                      
                                      }
                                      

                                      for do that , u tell me to created the member in window1.h :

                                      Window018703* window1::get_window018703() const
                                      {
                                          return window018703;
                                      
                                      }
                                      

                                      so after that, in the third class ( window018704)
                                      I try to recover this instance to call slot increment my display ... but i can not.

                                      I don't want to created or recover this instance in my main because the connect are in the third class ... so I think it is necessary to recover instance ( window018703) in the third class .

                                      you understand or it's not clear ??

                                      Thank for your time, and sorry for that late response ..

                                      1 Reply Last reply
                                      0
                                      • martial123M Offline
                                        martial123M Offline
                                        martial123
                                        wrote on last edited by
                                        #24

                                        no ideas ?

                                        SGaistS 1 Reply Last reply
                                        0
                                        • martial123M martial123

                                          no ideas ?

                                          SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #25

                                          Hi,

                                          @martial123 said in Refresh QLCDNumber:

                                          no ideas ?

                                          Please show some patience and allow 24 hours to pass before bumping your own thread. People answering here do it on their own time and may not live in the same time zone as you.

                                          As for your problem, currently your code is pretty convoluted.

                                          Can you describe what your application is doing and the responsibility of the various widget ?
                                          Also, please, give your class more meaningful names. Windows1, Window018703 and Window018704 doesn't really help at all understanding the relation between your widgets.

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          2

                                          • Login

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