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. How can I get my MainWindow to update?

How can I get my MainWindow to update?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 6.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SteveFerry
    wrote on last edited by
    #1

    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
    0
    • G Offline
      G Offline
      GrahamL
      wrote on last edited by
      #2

      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
      0
      • G GrahamL

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

        HTH

        S Offline
        S Offline
        SteveFerry
        wrote on last edited by
        #3

        @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
        0
        • G Offline
          G Offline
          GrahamL
          wrote on last edited by
          #4

          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
          1
          • G GrahamL

            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 Offline
            S Offline
            SteveFerry
            wrote on last edited by
            #5

            @GrahamL Thanks for the advice.

            I will try that later. Steve.

            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