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 access values in QVector from other cpp files

How to access values in QVector from other cpp files

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 307 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.
  • K Offline
    K Offline
    Ketank16
    wrote on last edited by Ketank16
    #1

    Good afternoon,

    Here's what I intend to do: I have a class SERIAL which contains 8 QVectors that hold values I'm receiving over serial port.

    class SERIAL : public QObject
    {
        Q_OBJECT
    
    private:
     
    public:
        SERIAL();
        ~SERIAL();
        QVector<double> ch0_array, mean_ch0_array,
                        ch1_array, mean_ch1_array,
                        ch2_array, mean_ch2_array,
                        ch3_array, mean_ch3_array,
                        ch4_array, mean_ch4_array,
                        ch5_array, mean_ch5_array,
                        ch6_array, mean_ch6_array,
                        ch7_array, mean_ch7_array;
    }
    

    I want to plot each set of data in real time in 8 other classes each with its own QDialog, called plot0 to plot8. But I'm not able to understand how to share the data from this class to other classes.
    I've tried including serial.h file to plot cpp files and I'm not able to access the vectors from there because of the error invalid use of non static data member.

    Does anyone have an idea about this as I'm pretty bad in C++.

    Pl45m4P 1 Reply Last reply
    0
    • K Ketank16

      Good afternoon,

      Here's what I intend to do: I have a class SERIAL which contains 8 QVectors that hold values I'm receiving over serial port.

      class SERIAL : public QObject
      {
          Q_OBJECT
      
      private:
       
      public:
          SERIAL();
          ~SERIAL();
          QVector<double> ch0_array, mean_ch0_array,
                          ch1_array, mean_ch1_array,
                          ch2_array, mean_ch2_array,
                          ch3_array, mean_ch3_array,
                          ch4_array, mean_ch4_array,
                          ch5_array, mean_ch5_array,
                          ch6_array, mean_ch6_array,
                          ch7_array, mean_ch7_array;
      }
      

      I want to plot each set of data in real time in 8 other classes each with its own QDialog, called plot0 to plot8. But I'm not able to understand how to share the data from this class to other classes.
      I've tried including serial.h file to plot cpp files and I'm not able to access the vectors from there because of the error invalid use of non static data member.

      Does anyone have an idea about this as I'm pretty bad in C++.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Ketank16

      Hi,

      first of all: your vectors belong inside the private section :) Then access them with get functions.

      @Ketank16 said in How to access values in QVector from other cpp files:

      I want to plot each set of data in real time

      You could send the data by Signal&Slot mechanism
      https://doc.qt.io/qt-5/signalsandslots.html

      What does your QDialog look like? Standard QDialog? What class / tool do you use for plotting?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

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

        Hi,

        Based on your description, I would recommend going the model view way. That will allow you to have a cleaner structure and way to share your data.

        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
        5

        • Login

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