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 get data read from tcp to display on Qchart?
Forum Updated to NodeBB v4.3 + New Features

How to get data read from tcp to display on Qchart?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 928 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #2

    Hi and welcome to the forums

    Its not clear if you want to read from TCP or from a file.
    Also , you talk about QChart, but then use a text browser in code.

    Also what type of chart do you want ?

    Did you look at the examples ?
    https://doc-snapshots.qt.io/qt5-5.15/qtcharts-examples.html

    B 1 Reply Last reply
    1
    • mrjjM mrjj

      Hi and welcome to the forums

      Its not clear if you want to read from TCP or from a file.
      Also , you talk about QChart, but then use a text browser in code.

      Also what type of chart do you want ?

      Did you look at the examples ?
      https://doc-snapshots.qt.io/qt5-5.15/qtcharts-examples.html

      B Offline
      B Offline
      bunnyb
      wrote on last edited by
      #3

      @mrjj hi, I want to read my data from TCP, however I cant seem to do it. I would like to use QLinechart but i dont seem to be able to append my data from TCP to chart.

      QChart *ThemeWidgetMedium::createLineChart() const
      {

      QChart *chart = new QChart();
      chart->setTitle("Line chart");
      
      QString name("Series ");
      int nameIndex = 0;
      for (const DataList &list : m_dataTable) {
          QLineSeries *series = new QLineSeries(chart);
          for (const Data &data : list)
              series->append(data.first);
          series->setName(name + QString::number(nameIndex));
          nameIndex++;
          chart->addSeries(series);
      }
      
      chart->createDefaultAxes();
      chart->axes(Qt::Horizontal).first()->setRange(0, m_valueMax);
      chart->axes(Qt::Vertical).first()->setRange(0, m_valueCount);
      
      // Add space to label to add space between labels and axis
      QValueAxis *axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first());
      Q_ASSERT(axisY);
      axisY->setLabelFormat("%.1f  ");
      //![4]
      
      return chart;
      

      }

      I felt that I cant get the data to enter my themewidget, hence i decided to work on displaying my data on textbrowser to ensure that my data is in the file.

      QStringList strings;
      for (int b=0;b<=20;b++){
          strings<<data[b];
          m_ui->textBrowser->setText(strings.join("\n"));
      }
      

      but the data array is highlighted meaning the data is not located inside my widget. hope this is better

      jsulmJ 1 Reply Last reply
      0
      • B bunnyb

        @mrjj hi, I want to read my data from TCP, however I cant seem to do it. I would like to use QLinechart but i dont seem to be able to append my data from TCP to chart.

        QChart *ThemeWidgetMedium::createLineChart() const
        {

        QChart *chart = new QChart();
        chart->setTitle("Line chart");
        
        QString name("Series ");
        int nameIndex = 0;
        for (const DataList &list : m_dataTable) {
            QLineSeries *series = new QLineSeries(chart);
            for (const Data &data : list)
                series->append(data.first);
            series->setName(name + QString::number(nameIndex));
            nameIndex++;
            chart->addSeries(series);
        }
        
        chart->createDefaultAxes();
        chart->axes(Qt::Horizontal).first()->setRange(0, m_valueMax);
        chart->axes(Qt::Vertical).first()->setRange(0, m_valueCount);
        
        // Add space to label to add space between labels and axis
        QValueAxis *axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first());
        Q_ASSERT(axisY);
        axisY->setLabelFormat("%.1f  ");
        //![4]
        
        return chart;
        

        }

        I felt that I cant get the data to enter my themewidget, hence i decided to work on displaying my data on textbrowser to ensure that my data is in the file.

        QStringList strings;
        for (int b=0;b<=20;b++){
            strings<<data[b];
            m_ui->textBrowser->setText(strings.join("\n"));
        }
        

        but the data array is highlighted meaning the data is not located inside my widget. hope this is better

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @bunnyb Where do you read data from TCP?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        B 1 Reply Last reply
        0
        • jsulmJ jsulm

          @bunnyb Where do you read data from TCP?

          B Offline
          B Offline
          bunnyb
          wrote on last edited by
          #5

          @jsulm its in another .cpp file

          void TCPConsole::putData(const QByteArray &data)
          {
          insertPlainText(data);

          QScrollBar *bar = verticalScrollBar();
          bar->setValue(bar->maximum());
          

          }

          jsulmJ 1 Reply Last reply
          0
          • B bunnyb

            @jsulm its in another .cpp file

            void TCPConsole::putData(const QByteArray &data)
            {
            insertPlainText(data);

            QScrollBar *bar = verticalScrollBar();
            bar->setValue(bar->maximum());
            

            }

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @bunnyb I don't see anything related to TCP in that code...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bunnyb
              wrote on last edited by
              #7

              #define TCPCONSOLE_H

              #include <QPlainTextEdit>
              #include <QDebug>

              class TCPConsole : public QPlainTextEdit
              {
              Q_OBJECT

              signals:
              void getData(const QByteArray &data);

              public:
              explicit TCPConsole(QWidget *parent = nullptr);

              void putData(const QByteArray &data);
              void setLocalEchoEnabled(bool set);
              

              protected:
              void keyPressEvent(QKeyEvent *e) override;
              void mousePressEvent(QMouseEvent *e) override;
              void mouseDoubleClickEvent(QMouseEvent *e) override;
              void contextMenuEvent(QContextMenuEvent *e) override;

              private:
              bool m_localEchoEnabled = false;
              };

              #endif // TCPCONSOLE_H

              can i check usually the data is get from the function i call that is public means all files can use? or signals?

              jsulmJ 1 Reply Last reply
              0
              • B bunnyb

                #define TCPCONSOLE_H

                #include <QPlainTextEdit>
                #include <QDebug>

                class TCPConsole : public QPlainTextEdit
                {
                Q_OBJECT

                signals:
                void getData(const QByteArray &data);

                public:
                explicit TCPConsole(QWidget *parent = nullptr);

                void putData(const QByteArray &data);
                void setLocalEchoEnabled(bool set);
                

                protected:
                void keyPressEvent(QKeyEvent *e) override;
                void mousePressEvent(QMouseEvent *e) override;
                void mouseDoubleClickEvent(QMouseEvent *e) override;
                void contextMenuEvent(QContextMenuEvent *e) override;

                private:
                bool m_localEchoEnabled = false;
                };

                #endif // TCPCONSOLE_H

                can i check usually the data is get from the function i call that is public means all files can use? or signals?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @bunnyb Sorry, but this also has absolutely nothing to do with reading data from TCP! So, do you really read data from network (TCP) or what do you mean if you say TCP?

                "can i check usually the data is get from the function i call that is public means all files can use?" - can you please rephrase? I don't understand this. Public method can be called by everyone who has access to the instance...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bunnyb
                  wrote on last edited by
                  #9

                  oh i see. May i know how QT5 printf in widget? Example in python we use print("hello world");

                  jsulmJ 1 Reply Last reply
                  0
                  • B bunnyb

                    oh i see. May i know how QT5 printf in widget? Example in python we use print("hello world");

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @bunnyb said in How to get data read from tcp to display on Qchart?:

                    printf in widget?

                    What widget do you mean exactly? If you want to show some text in your UI you can use https://doc.qt.io/qt-5/qlabel.html
                    If you want to print to stdout simply use std::cout.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      bunnyb
                      wrote on last edited by
                      #11

                      Based on my understanding, qlabel, textbrowser only takes in QString correct? If i would like to display a QArrayByte is it possible?

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

                        Hi,

                        Sure it is, convert it to a QString. Just beware that depending on the content, it might have surprising results.

                        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
                        1

                        • Login

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