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. Refresh QLCDNumber

Refresh QLCDNumber

Scheduled Pinned Locked Moved Solved General and Desktop
36 Posts 3 Posters 7.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 Offline
    martial123M Offline
    martial123
    wrote on last edited by
    #1

    Hi ,
    I have a probleme with a QLCDNumber.
    When i want to refresh is value with connect in other class, nothing is appening...
    also I want to incremented his value too but i don't know how i can do that .. (like, each passage in the slot, display(value ++) )

    this is my slot who receive signal :

    void Window018703::set_lcdNumber_seatUp(int a)
    {
        int B = 1;
        ui->lcdNumber_seatUp->display(B);
    }
    

    class who call slot on push on button :

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

    class who countain slot receiver :

    #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(int a)
    {
        int B = 1;
        cout << " önt rentre ici et a vaut = " << B << endl;
        ui->lcdNumber_seatUp->display(B);
    }
    

    Thank you for your help
    Martial

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

      Hi
      One thing.
      Button click do not have parameter but you slot has
      QObject::connect(ui->pushButton_018704, &QPushButton::clicked , window018703, &Window018703::set_lcdNumber_seatUp);

      void Window018703::set_lcdNumber_seatUp(int a) <<< int a is not valid
      {
          int B = 1;
          cout << " önt rentre ici et a vaut = " << B << endl;
          ui->lcdNumber_seatUp->display(B);
      }
      
      • also I want to incremented his value too but i don't know how i can do that .. (like, each passage in the slot, display(value ++) )

      One option is to do

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

      that would keep raising B on each call till program ends.

      martial123M 1 Reply Last reply
      3
      • mrjjM mrjj

        Hi
        One thing.
        Button click do not have parameter but you slot has
        QObject::connect(ui->pushButton_018704, &QPushButton::clicked , window018703, &Window018703::set_lcdNumber_seatUp);

        void Window018703::set_lcdNumber_seatUp(int a) <<< int a is not valid
        {
            int B = 1;
            cout << " önt rentre ici et a vaut = " << B << endl;
            ui->lcdNumber_seatUp->display(B);
        }
        
        • also I want to incremented his value too but i don't know how i can do that .. (like, each passage in the slot, display(value ++) )

        One option is to do

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

        that would keep raising B on each call till program ends.

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

        @mrjj

        Thank you for your response, the increment work well when the connect and slot are in the same class, when I try to call this slot by an other class, this doesn't work ...

        mrjjM 1 Reply Last reply
        0
        • martial123M martial123

          @mrjj

          Thank you for your response, the increment work well when the connect and slot are in the same class, when I try to call this slot by an other class, this doesn't work ...

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

          @martial123
          It should work the same.
          Are you sure its the right one, you are looking at ?
          Yo create a new window here
          Window018703 *window018703 = new Window018703(); <<< new window
          QObject::connect(ui->pushButton_018704, &QPushButton::clicked , window018703, &Window018703::set_lcdNumber_seatUp);
          but you dont seem to show it so i wonder if you already made one somewhere else
          and are looking at that ?

          martial123M 1 Reply Last reply
          0
          • mrjjM mrjj

            @martial123
            It should work the same.
            Are you sure its the right one, you are looking at ?
            Yo create a new window here
            Window018703 *window018703 = new Window018703(); <<< new window
            QObject::connect(ui->pushButton_018704, &QPushButton::clicked , window018703, &Window018703::set_lcdNumber_seatUp);
            but you dont seem to show it so i wonder if you already made one somewhere else
            and are looking at that ?

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

            @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 1 Reply Last reply
            0
            • 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

                                          • Login

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