Nominate our 2022 Qt Champions!

How to input numbers to QLCD in QT?

  • Hi everyone, I have been reading the forum with regards the QT and I finally cant contained myself and require assistance.

    Situation: I have design an ui with qt designer. There is presumably no problem with the design. However the .cpp and.h might be the ultimate problem. My goal is to insert number through signals and slots (Since its QT?)

    Here are my codes i been working on

    #include "mainwindow.h"
    #include <QApplication>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;;
        return a.exec();

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QLCDNumber>

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)


    connect(this, SIGNAL(UpdateValFunc(float NewTESTno),ui->testQLCD, SLOT(display(TESTno)));


    delete ui;



    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include <QLCDNumber>
    namespace Ui {
    class MainWindow;
    class QLCDNumber;
    class QTimer;
    class QWidget;
    class MainWindow :  public QMainWindow
        explicit MainWindow(QWidget *parent = 0);
        float TESTno = 1.0;
        void UpdateValFunc(float NewTESTno);
        Ui::MainWindow *ui;
    #endif // MAINWINDOW_H
    I got many other questions but this will do for now.
    Some other qn: change QLCD,  why the signal are limited? how do I put in function as signal? the higher form of stacks widget. Thank you!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You likely have a runtime warning tell you that the connection failed. You don't pass variable in the parameters you pass to the SIGNAL and SLOTS macros.

    Please see the corresponding chapter in Qt's documentation.

  • Hi, thank you for your reply. I realised my post have some missing words and syntax. Doesn't matter.

    Is there an example where I can utilise/input a function into a signal ? I tried not passing a variable in the void UpdateValFunc() . There is no error but nothing changed.

    I also suspect there might be some error in the "connect" syntax since I am not sure what signal to place under the syntax for the function. Looking forward for your reply and will re-read the documentation.

  • Lifetime Qt Champion

    @Faruq said in How to input numbers to QLCD in QT?:

    is there an example where I can utilise/input a function into a signal ?

    Im not sure what you mean ?
    The signals are sent to socalled slots, which is just a normal c++ member function that
    you define.

    When signal is then sent, the slot is called.

    For your code to work, which seems that
    mainwindow has new signal
    void UpdateValFunc(float NewTESTno);
    that you want to use with
    QLCDNumber's display(double num) (slot)

    You connect should be
    connect(this, SIGNAL(UpdateValFunc(float ),ui->testQLCD, SLOT(display(double)));

    But for anything to happen. someone must emit the signal

    void MainWindow::SomeButtonClick() {
    emit UpdateValFunc(100.10);

  • Thanks for your reply.

    So that means I am unable to connect a function into a SIGNAL as there is nothing to trigger the function?

    If that the case, it will lead me back to the question: how do I input the numbers into QLCDNumber without the connect function??

    I tried putting some numbers into the

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow){

    platform. But I believe having a function for information from other file to input into this function is more reliable.

  • Lifetime Qt Champion

    @Faruq said in How to input numbers to QLCD in QT?:

    So that means I am unable to connect a function into a SIGNAL as there is nothing to trigger the function?

    Well, you connect SIGNALS to functions (slots) and not the other way around.

    so someone must emit UpdateValFunc for anything to happen.
    It simply cannot work without.
    Someone must send the signal to have the slot called.

    Just like someone must CALL a function, to have that function run.

    why don't you simply just set the value you want ?


    no need for signals for that.
    Slots are normal c++ functions and you are allowed to just call them :)

  • @mrjj Ah yes. Thank you for your reply. After a long hours of meditation, I start to understand what I do wrong. Hmm and yeap I do what you have suggest. The reason being is that I will want to input values from other file to be inserted into this Function. That is what I am trying to do :)

    (let me write according to my memory)
    ***where Function is values from other files or real time data.

    What do you think about this? :)

    PS: To all: Thank you everyone, I am a step closer to finishing this task of mine. Now I am trying to figure how to minimise or show QMainWindow. Trying to understand the mechanics behind it. This I will put it in other post if I am stucked at this level for a long time.

  • Lifetime Qt Champion

    You mean like
    double GetMydata() { read from file... return Var }

    ui->lcdNumber->display( GetMydata() ); // assign the return value from the function

  • yup! Will figure it out first :) Thank you!

Log in to reply