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. QTimer and QLCDNumber not working correctly together.
Forum Updated to NodeBB v4.3 + New Features

QTimer and QLCDNumber not working correctly together.

Scheduled Pinned Locked Moved General and Desktop
qtimerqlcdnumbertimer
4 Posts 2 Posters 2.4k Views 2 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.
  • J Offline
    J Offline
    Jorge
    wrote on 19 Jun 2015, 20:06 last edited by Jorge
    #1

    Hi,
    I'm trying to simulate the pulses of a machine we're building and I've decided to do it with a QTimer. I've read the documentation and I've seen how it works, however, I can't seem to get it to display in the QLCDNumber I want it to work with.
    I've tried with signals and slots, but in the end the QLCDOutpot is an "A".
    Here's the piece of my code where I attempt to make the connection, and then further where the methods are developed:

    //Part of the .cpp 
        timer = new QTimer(this);
    
        ui->lcdLitres->setStyleSheet("background-color: rgb(162, 195, 228)");
        ui->lcdPrice->setStyleSheet("background-color: rgb(162, 195, 228)");
        ui->btnStart->setStyleSheet("background-color: rgb(161, 249, 7)");
        ui->btnCancel->setStyleSheet("background-color: rgb(245, 1, 3)");
        ui->lcdLitres->setDigitCount(10);
        ui->lcdPrice->setDigitCount(10);
    
        connect(ui->btnStart, SIGNAL(clicked()),
                timer, SLOT(start()));
        connect(timer, SIGNAL(timeout()),
                this, SLOT(elapseLiters()));
    
    //Still .cpp
    void QDispenseDisplay::on_btnStart_clicked()
    {
        ui->btnCancel->setText("Detener");
        bCancelLoop = false;
    
        QSqlQuery query;
        query.exec("SELECT id, fPrecioUnit, fLitros, fImporte FROM Servicios WHERE id = last_insert_rowid()");
    
        query.next();
        QSqlRecord record = query.record();
        fUnitPrice = record.value(1).toFloat();
        fLitres = record.value(2).toFloat();
        fTotal = record.value(3).toFloat();
    
    //    qDebug() << "Last ID: " << sLastId;
        qDebug() << "fPrecioUnit: " << fUnitPrice;
        qDebug() << "fLitros: " << fLitres;
        qDebug() << "fImporte: " << fTotal;
    //    qDebug() << query.lastError();
    
        timer->setInterval(1000);
    
        QString sLitros = QString::number(fElapsedLitres, 'f', 2);
        QString sPrecio = QString::number(fUnitPrice * fElapsedLitres, 'f', 2);
    
        ui->lcdLitres->display(sLitros);
        ui->lcdPrice->display(sPrecio);
    
        if(fElapsedLitres == fLitres)
        {
            timer->stop();
        }
    }
    float QDispenseDisplay::getFElapsedLitres() const
    {
        return fElapsedLitres;
    }
    
    void QDispenseDisplay::setFElapsedLitres(float value)
    {
        fElapsedLitres = value;
    }
    
    
    void QDispenseDisplay::elapseLiters()
    {
        setFElapsedLitres(fElapsedLitres + 1);
    }
    
    
    //header file
    
    #ifndef QDISPENSEDISPLAY_H
    #define QDISPENSEDISPLAY_H
    
    #include <QWidget>
    #include <QTimer>
    #include <QLCDNumber>
    #include <QtSql>
    #include <QFileInfo>
    #include <QElapsedTimer>
    
    namespace Ui {
    class QDispenseDisplay;
    }
    
    class QDispenseDisplay : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit QDispenseDisplay(QWidget *parent = 0);
        ~QDispenseDisplay();
    
    
    
    public slots:
        void cancel(bool bCancel)
        {
            if ( bCancel != this->bCancel )
            {
                this->bCancel = bCancel;
                emit cancelling(this->bCancel);
                this->bCancel = false;
            }
        }
    
        void delay(int millisecondsToWait);
    
        void elapseLiters();
        float getFElapsedLitres() const;
        void setFElapsedLitres(float value);
    
    signals:
        cancelling(bool bCancel);
    
    private slots:
        void on_btnCancel_clicked();
    
        void on_btnNext_clicked();
    
        void on_btnStart_clicked();
    
    private:
        Ui::QDispenseDisplay *ui;
    
        bool bCancel;
    
        bool bCancelLoop;
    
        QTime *time;
    
        QTimer *timer;
    
        QElapsedTimer *eTimer;
    
        QSqlDatabase sqlLiquascanDB;
    
        float fUnitPrice;
        float fLitres;
        float fTotal;
    
        float fElapsedLitres;
    };
    
    #endif // QDISPENSEDISPLAY_H
    

    Summarizing (is that a word?), I want the QLCDNumber to display a simple tick every second and stop if it reaches the amount of fLitres.
    Thanks in advance.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 19 Jun 2015, 20:35 last edited by
      #2

      Hi,

      Unless I'm mistaken your QLCDNumber widget is in hexadecimal mode, change for Dec and you should be good to go.

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

      J 1 Reply Last reply 19 Jun 2015, 21:03
      0
      • S SGaist
        19 Jun 2015, 20:35

        Hi,

        Unless I'm mistaken your QLCDNumber widget is in hexadecimal mode, change for Dec and you should be good to go.

        J Offline
        J Offline
        Jorge
        wrote on 19 Jun 2015, 21:03 last edited by
        #3

        @SGaist Thanks for the reply.
        I've checked in the designer and it is set to "Dec". It still displays an "A". I´ve updated the signals and slots, but still nothing.

        void QDispenseDisplay::elapseLiters()
        {
            setFElapsedLitres(fElapsedLitres + 1);
            QString sLitros = QString::number(fElapsedLitres, 'f', 2);
            QString sPrecio = QString::number(fUnitPrice * fElapsedLitres, 'f', 2);
        
            ui->lcdLitres->display(sLitros);
            ui->lcdPrice->display(sPrecio);
        
            if(fElapsedLitres == fLitres)
            {
                timer->stop();
            }
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 19 Jun 2015, 21:33 last edited by
          #4

          When does it start to show that A ?

          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
          0

          4/4

          19 Jun 2015, 21:33

          • Login

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