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. [beginner] Displaying data from a class C++
Forum Update on Monday, May 27th 2025

[beginner] Displaying data from a class C++

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.1k 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.
  • M Offline
    M Offline
    MKUltra
    wrote on last edited by
    #1

    Hi all,
    I'm trying to create a program that displays live data from a Myo armband. I have a class DataCollector that inherits from QObject and myo::DeviceListener which collects information from the band and updates some int variables, I then just want these variables to be displayed by separate LCDNumber components in a class GUItest that inherits from QMainWindow.

    What is the best way about this to go about this? I think I'm getting confused with the signals and slots.

    // This is a snippet of my code:

    public:
    int value() const { return emgMax; }

    public slots:
    void setMaxValue(int value)
    {
    if (value != emgMax){
    emgMax = value;
    emit valueChanged(value);
    }
    }

    signals:
    void valueChanged(int newValue);

    private:
    int emgMax;

    // this is the connection
    connect(&collector, &DataCollector::valueChanged, ui.lcdMax, SLOT(display(int)));

    // this is the call within dataCollector
    if (emgSum > emgMax)
    {
    setMaxValue(emgSum);
    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      // this looks wrong
      connect(&collector, &DataCollector::valueChanged, ui.lcdMax, SLOT(display(int)));
      
      connect(&collector, &DataCollector::valueChanged, ui.lcdMax, static_cast<void (QLCDNumber::*)(int)>(&QLCDNumber::display));
      

      However are you sure that collector lives long enough ?

      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
      • M Offline
        M Offline
        MKUltra
        wrote on last edited by
        #3

        Thank you for your response. The compiler likes your connect statement.

        But yes, I am now unsure about the collector's life. I have the collector as an uninitialized attribute in the class GUItest then in the constructor I handle the connection.

        Where is the program flow after "return a.exec();" is reached? is there away I can just have a loop and update the lcd displays every second? As the data being collected changes in the milliseconds

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can use a QTimer if you want to update at a fixed interval

          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

          • Login

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