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 to input numbers to QLCD in QT?
QtWS25 Last Chance

How to input numbers to QLCD in QT?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 3.2k 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.
  • F Offline
    F Offline
    Faruq
    wrote on 10 May 2018, 08:54 last edited by
    #1

    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;
        w.show();
    
        return a.exec();
    }
    
    
    //mainwindow.cpp
    

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

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    ui->testQLCD->display(TESTno);
    

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

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    
    

    //mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QLCDNumber>
    
    namespace Ui {
    class MainWindow;
    class QLCDNumber;
    class QTimer;
    class QWidget;
    }
    
    class MainWindow :  public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
        float TESTno = 1.0;
    
    signals:
        void UpdateValFunc(float NewTESTno);
    
    private:
        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!
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 May 2018, 22:15 last edited by
      #2

      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.

      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
      • F Offline
        F Offline
        Faruq
        wrote on 10 May 2018, 23:20 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 11 May 2018, 00:08 last edited by
          #4

          @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

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

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Faruq
            wrote on 11 May 2018, 01:17 last edited by
            #5

            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) :
            QMainWindow(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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 11 May 2018, 07:38 last edited by mrjj 5 Nov 2018, 07:38
              #6

              @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.

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

              ui->lcdNumber->display(100.10);

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

              F 1 Reply Last reply 11 May 2018, 09:16
              0
              • M mrjj
                11 May 2018, 07:38

                @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.

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

                ui->lcdNumber->display(100.10);

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

                F Offline
                F Offline
                Faruq
                wrote on 11 May 2018, 09:16 last edited by
                #7

                @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)
                ui->QLCD->Display(Function)
                ***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.

                M 1 Reply Last reply 11 May 2018, 09:19
                1
                • F Faruq
                  11 May 2018, 09:16

                  @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)
                  ui->QLCD->Display(Function)
                  ***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.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 11 May 2018, 09:19 last edited by
                  #8

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

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

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    Faruq
                    wrote on 13 May 2018, 05:23 last edited by
                    #9

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

                    1 Reply Last reply
                    0

                    1/9

                    10 May 2018, 08:54

                    • Login

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