Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How can I get my MainWindow to update?

    General and Desktop
    2
    5
    5430
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      SteveFerry last edited by

      Hello, I'm new to Qt. In the past I have used C/C++ for about 30 years and have also developed windows apps using VB. Now, I'm tinkering with a Raspberry Pi and Qt.

      I developed an 8 channel ADC board and have written routines to read data from it using direct register access. Some of these routines are quite complex doing fourier transforms etc. before saving the data to a file. I now want to start using Qt and my first attempt is a very simple voltmeter. I put a lcdNumber on my MainWindow and used the following code to display a value from the adc

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include "adcio.cpp"

      MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
      {
      ui->setupUi(this);
      gpioGetHWRev();
      ui->lcdNumber->display((double) ((val3208(0,0)*3.3)/4096.0));

      }

      This works. The next step is to continuously read the adc and update the lcdNumber until I exit the program. I tried putting the 'ui->lcdNumer' line into a loop but it doesn't update the display until the loop ends.

      Any advice on how to accomplish this?

      Thanks, Steve.

      1 Reply Last reply Reply Quote 0
      • G
        GrahamL last edited by

        Hi
        Maybe you could use a QTimer set to go off at a suitable interval and the update the UI

        HTH

        S 1 Reply Last reply Reply Quote 0
        • S
          SteveFerry @GrahamL last edited by

          @GrahamL Thanks for your reply. I did wonder about using QTimer. I found this example

          MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
          {
          ui->setupUi(this);
          QTimer::singleShot(5, this, SLOT(timeout());
          }

          I assume I would have to create a slot such as this;

          void MainWindow::timeout()
          {
          ui->lcdNumber->display((double) ((val3208(0,0)*3.3)/4096.0));
          }

          Is this what you would suggest? otherwise, how would you accomplish it with QTimer?

          Steve.

          1 Reply Last reply Reply Quote 0
          • G
            GrahamL last edited by

            Hi
            I would have a QTimer member in MainWindow and initialise it and start it for the desired interval. Then you need to supply a slot that is executed when the timer fires.
            So in MainWindow.h

            QTimer* m_timer;
            
            slots:
            void update();
            

            and in MainWindow.cpp

            m_timer = new QTimer(this);
            connect (m_timer,&QTimer::timeout,this,&MainWindow::update);
            m_timer->start(1000); // for a 1 second interval
            

            HTH

            S 1 Reply Last reply Reply Quote 1
            • S
              SteveFerry @GrahamL last edited by

              @GrahamL Thanks for the advice.

              I will try that later. Steve.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post