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. Creating a chart with multiple datas

Creating a chart with multiple datas

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5chart
29 Posts 3 Posters 4.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.
  • D deleted286
    26 Jan 2021, 12:55

    @jsulm But i have 4 different queue, all them should be parameter?

    P Offline
    P Offline
    Pl45m4
    wrote on 26 Jan 2021, 13:04 last edited by
    #8

    @suslucoder said in Creating a chart with multiple datas:

    But i have 4 different queue, all them should be parameter?

    Just loop your queues.

    Bad:

    if(!queue1.isEmpty())
        {
           double num=queue1.dequeue();
        }
    if(!queue2.isEmpty())
        {
           double num=queue2.dequeue();
        }
    if(!queue3.isEmpty())
        {
           double num=queue3.dequeue();
        }
    

    Better:

    // Container with all your data or just pass one QQueue after another to your function
    QVector<QQueue<double> > data;
    
    for(int i = 0; i < data.size(); i++)
    {
       if(!data.at(i).isEmpty())
        {
           double num=data.at(i).dequeue();
           // ...
        }
    
    }
    

    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
    2
    • D deleted286
      26 Jan 2021, 12:55

      @jsulm But i have 4 different queue, all them should be parameter?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 26 Jan 2021, 13:13 last edited by
      #9

      @suslucoder said in Creating a chart with multiple datas:

      But i have 4 different queue, all them should be parameter?

      Yes, that's the idea:

      void MainWindow::someMethod(const QQueue<double> &queue)
      {
      ...
      }
      ...
      someMethod(queue);
      someMethod(queue1);
      someMethod(queue2);
      someMethod(queue3);
      

      Or do it like @Pl45m4 suggested.

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

      D 1 Reply Last reply 26 Jan 2021, 13:20
      2
      • J jsulm
        26 Jan 2021, 13:13

        @suslucoder said in Creating a chart with multiple datas:

        But i have 4 different queue, all them should be parameter?

        Yes, that's the idea:

        void MainWindow::someMethod(const QQueue<double> &queue)
        {
        ...
        }
        ...
        someMethod(queue);
        someMethod(queue1);
        someMethod(queue2);
        someMethod(queue3);
        

        Or do it like @Pl45m4 suggested.

        D Offline
        D Offline
        deleted286
        wrote on 26 Jan 2021, 13:20 last edited by
        #10

        @jsulm I understand it now. How about the reading part?
        Can i do it like queue part?

        J 1 Reply Last reply 26 Jan 2021, 13:24
        0
        • D deleted286
          26 Jan 2021, 13:20

          @jsulm I understand it now. How about the reading part?
          Can i do it like queue part?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 26 Jan 2021, 13:24 last edited by
          #11

          @suslucoder said in Creating a chart with multiple datas:

          Can i do it like queue part?

          Why not?

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

          D 1 Reply Last reply 26 Jan 2021, 13:46
          0
          • J jsulm
            26 Jan 2021, 13:24

            @suslucoder said in Creating a chart with multiple datas:

            Can i do it like queue part?

            Why not?

            D Offline
            D Offline
            deleted286
            wrote on 26 Jan 2021, 13:46 last edited by
            #12

            @jsulm is it true?

            void MainWindow::ReadFile()
            {
                  QFile file("/home/ilknur/Chart/Data1.txt");
                  QFile file2("/home/ilknur/Chart/Data2.txt");
                  QFile file3("/home/ilknur/Chart/Data3.txt");
                  QFile file4("/home/ilknur/Chart/Data4.txt");
            
                   if(file.open(QIODevice::ReadOnly))
                   {
                       QTextStream in(&file);
                       while (!in.atEnd()) {
                           QString line = in.readLine();
                           QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
                           for (const QString &entry : list)
                           {
                               double num = entry.toDouble();
                               qDebug() << num;
                               queue.enqueue(num);
                           }
                       }
                   }
            
                   if(file2.open(QIODevice::ReadOnly))
                   {
                       QTextStream in(&file2);
                       while (!in.atEnd()) {
                           QString line2 = in.readLine();
                           QStringList list2 = line2.split(QLatin1Char(' '), QString::SkipEmptyParts);
                           for (const QString &entry : list2)
                           {
                               double num2 = entry.toDouble();
                               qDebug() << num2;
                               queue2.enqueue(num2);
                           }
                       }
                   }
            
                   if(file3.open(QIODevice::ReadOnly))
                   {
                       QTextStream in(&file3);
                       while (!in.atEnd()) {
                           QString line3 = in.readLine();
                           QStringList list3 = line3.split(QLatin1Char(' '), QString::SkipEmptyParts);
                           for (const QString &entry : list3)
                           {
                               double num3 = entry.toDouble();
                               qDebug() << num3;
                               queue3.enqueue(num3);
                           }
                       }
                   }
            
                   if(file4.open(QIODevice::ReadOnly))
                   {
                       QTextStream in(&file4);
                       while (!in.atEnd()) {
                           QString line4 = in.readLine();
                           QStringList list4 = line4.split(QLatin1Char(' '), QString::SkipEmptyParts);
                           for (const QString &entry : list4)
                           {
                               double num4 = entry.toDouble();
                               qDebug() << num4;
                               queue4.enqueue(num4);
                           }
                       }
                   }
            }
            
            J P 2 Replies Last reply 26 Jan 2021, 13:47
            0
            • D deleted286
              26 Jan 2021, 13:46

              @jsulm is it true?

              void MainWindow::ReadFile()
              {
                    QFile file("/home/ilknur/Chart/Data1.txt");
                    QFile file2("/home/ilknur/Chart/Data2.txt");
                    QFile file3("/home/ilknur/Chart/Data3.txt");
                    QFile file4("/home/ilknur/Chart/Data4.txt");
              
                     if(file.open(QIODevice::ReadOnly))
                     {
                         QTextStream in(&file);
                         while (!in.atEnd()) {
                             QString line = in.readLine();
                             QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
                             for (const QString &entry : list)
                             {
                                 double num = entry.toDouble();
                                 qDebug() << num;
                                 queue.enqueue(num);
                             }
                         }
                     }
              
                     if(file2.open(QIODevice::ReadOnly))
                     {
                         QTextStream in(&file2);
                         while (!in.atEnd()) {
                             QString line2 = in.readLine();
                             QStringList list2 = line2.split(QLatin1Char(' '), QString::SkipEmptyParts);
                             for (const QString &entry : list2)
                             {
                                 double num2 = entry.toDouble();
                                 qDebug() << num2;
                                 queue2.enqueue(num2);
                             }
                         }
                     }
              
                     if(file3.open(QIODevice::ReadOnly))
                     {
                         QTextStream in(&file3);
                         while (!in.atEnd()) {
                             QString line3 = in.readLine();
                             QStringList list3 = line3.split(QLatin1Char(' '), QString::SkipEmptyParts);
                             for (const QString &entry : list3)
                             {
                                 double num3 = entry.toDouble();
                                 qDebug() << num3;
                                 queue3.enqueue(num3);
                             }
                         }
                     }
              
                     if(file4.open(QIODevice::ReadOnly))
                     {
                         QTextStream in(&file4);
                         while (!in.atEnd()) {
                             QString line4 = in.readLine();
                             QStringList list4 = line4.split(QLatin1Char(' '), QString::SkipEmptyParts);
                             for (const QString &entry : list4)
                             {
                                 double num4 = entry.toDouble();
                                 qDebug() << num4;
                                 queue4.enqueue(num4);
                             }
                         }
                     }
              }
              
              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 26 Jan 2021, 13:47 last edited by jsulm
              #13

              @suslucoder said in Creating a chart with multiple datas:

              is it true?

              Of course not!
              You again copy same code several times.
              You already was shown how to do this correctly, I'm not going to explain the same second time...

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

              D 1 Reply Last reply 26 Jan 2021, 13:52
              0
              • J jsulm
                26 Jan 2021, 13:47

                @suslucoder said in Creating a chart with multiple datas:

                is it true?

                Of course not!
                You again copy same code several times.
                You already was shown how to do this correctly, I'm not going to explain the same second time...

                D Offline
                D Offline
                deleted286
                wrote on 26 Jan 2021, 13:52 last edited by
                #14

                @jsulm Can you explain it please for last time :(

                J 1 Reply Last reply 26 Jan 2021, 13:53
                0
                • D deleted286
                  26 Jan 2021, 13:52

                  @jsulm Can you explain it please for last time :(

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 26 Jan 2021, 13:53 last edited by
                  #15

                  @suslucoder No, I did it above already...

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

                  1 Reply Last reply
                  0
                  • D deleted286
                    26 Jan 2021, 13:46

                    @jsulm is it true?

                    void MainWindow::ReadFile()
                    {
                          QFile file("/home/ilknur/Chart/Data1.txt");
                          QFile file2("/home/ilknur/Chart/Data2.txt");
                          QFile file3("/home/ilknur/Chart/Data3.txt");
                          QFile file4("/home/ilknur/Chart/Data4.txt");
                    
                           if(file.open(QIODevice::ReadOnly))
                           {
                               QTextStream in(&file);
                               while (!in.atEnd()) {
                                   QString line = in.readLine();
                                   QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                   for (const QString &entry : list)
                                   {
                                       double num = entry.toDouble();
                                       qDebug() << num;
                                       queue.enqueue(num);
                                   }
                               }
                           }
                    
                           if(file2.open(QIODevice::ReadOnly))
                           {
                               QTextStream in(&file2);
                               while (!in.atEnd()) {
                                   QString line2 = in.readLine();
                                   QStringList list2 = line2.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                   for (const QString &entry : list2)
                                   {
                                       double num2 = entry.toDouble();
                                       qDebug() << num2;
                                       queue2.enqueue(num2);
                                   }
                               }
                           }
                    
                           if(file3.open(QIODevice::ReadOnly))
                           {
                               QTextStream in(&file3);
                               while (!in.atEnd()) {
                                   QString line3 = in.readLine();
                                   QStringList list3 = line3.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                   for (const QString &entry : list3)
                                   {
                                       double num3 = entry.toDouble();
                                       qDebug() << num3;
                                       queue3.enqueue(num3);
                                   }
                               }
                           }
                    
                           if(file4.open(QIODevice::ReadOnly))
                           {
                               QTextStream in(&file4);
                               while (!in.atEnd()) {
                                   QString line4 = in.readLine();
                                   QStringList list4 = line4.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                   for (const QString &entry : list4)
                                   {
                                       double num4 = entry.toDouble();
                                       qDebug() << num4;
                                       queue4.enqueue(num4);
                                   }
                               }
                           }
                    }
                    
                    P Offline
                    P Offline
                    Pl45m4
                    wrote on 26 Jan 2021, 13:54 last edited by Pl45m4
                    #16

                    @suslucoder

                    QString file("/home/ilknur/Chart/Data1.txt");
                    // ...
                    // ...
                    // all your files
                    
                    void MainWindow::ReadFile(QString file)
                    {
                      QFile(file);
                    
                           if(file.open(QIODevice::ReadOnly))
                           {
                               QTextStream in(&file);
                               while (!in.atEnd()) {
                                   QString line = in.readLine();
                                   QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                   for (const QString &entry : list)
                                   {
                                       double num = entry.toDouble();
                                       qDebug() << num;
                                        // pick correct queue here
                                       queue.enqueue(num);
                                   }
                               }
                           }
                    }
                    

                    Then just call this read function ones for every file you want to read (with the file path as argument)

                    ReadFile(file);
                    

                    Or even make a QStringList with all your filenames and call this function for every element of your list.

                    To write "good" and clean code (OOP programming) , you'll need to stop that linear thinking (like script language). And even most of the script languages nowadays have functions, which you can define, to avoid writing the same code over and over and over again.

                    Doing something X times != writing it X times.
                    It's all about effiency (trying to avoid unnecessary things that will waste time, space and hardware ressources at runtime)


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

                    ~E. W. Dijkstra

                    D 1 Reply Last reply 26 Jan 2021, 14:16
                    1
                    • P Pl45m4
                      26 Jan 2021, 13:54

                      @suslucoder

                      QString file("/home/ilknur/Chart/Data1.txt");
                      // ...
                      // ...
                      // all your files
                      
                      void MainWindow::ReadFile(QString file)
                      {
                        QFile(file);
                      
                             if(file.open(QIODevice::ReadOnly))
                             {
                                 QTextStream in(&file);
                                 while (!in.atEnd()) {
                                     QString line = in.readLine();
                                     QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                     for (const QString &entry : list)
                                     {
                                         double num = entry.toDouble();
                                         qDebug() << num;
                                          // pick correct queue here
                                         queue.enqueue(num);
                                     }
                                 }
                             }
                      }
                      

                      Then just call this read function ones for every file you want to read (with the file path as argument)

                      ReadFile(file);
                      

                      Or even make a QStringList with all your filenames and call this function for every element of your list.

                      To write "good" and clean code (OOP programming) , you'll need to stop that linear thinking (like script language). And even most of the script languages nowadays have functions, which you can define, to avoid writing the same code over and over and over again.

                      Doing something X times != writing it X times.
                      It's all about effiency (trying to avoid unnecessary things that will waste time, space and hardware ressources at runtime)

                      D Offline
                      D Offline
                      deleted286
                      wrote on 26 Jan 2021, 14:16 last edited by
                      #17

                      @Pl45m4 where should i store

                      QString file("/home/ilknur/Chart/Data1.txt");
                      // ...
                      // ...
                      // all your files
                      
                      

                      And i have 4 different files. In this case,

                      QString file("/home/ilknur/FourLineChart/Data1.txt");
                      QString file2("/home/ilknur/FourLineChart/Data2.txt");
                      QString file3("/home/ilknur/FourLineChart/Data3.txt");
                      QString file4("/home/ilknur/FourLineChart/Data4.txt");
                      
                      P 1 Reply Last reply 26 Jan 2021, 14:18
                      0
                      • D deleted286
                        26 Jan 2021, 14:16

                        @Pl45m4 where should i store

                        QString file("/home/ilknur/Chart/Data1.txt");
                        // ...
                        // ...
                        // all your files
                        
                        

                        And i have 4 different files. In this case,

                        QString file("/home/ilknur/FourLineChart/Data1.txt");
                        QString file2("/home/ilknur/FourLineChart/Data2.txt");
                        QString file3("/home/ilknur/FourLineChart/Data3.txt");
                        QString file4("/home/ilknur/FourLineChart/Data4.txt");
                        
                        P Offline
                        P Offline
                        Pl45m4
                        wrote on 26 Jan 2021, 14:18 last edited by
                        #18

                        @suslucoder said in Creating a chart with multiple datas:

                        where should i store

                        Do you even read what we wrote?

                        @Pl45m4 said in Creating a chart with multiple datas:

                        Then just call this read function ones for every file you want to read (with the file path as argument)
                        ReadFile(file);

                        Or even make a QStringList with all your filenames and call this function for every element of your list.

                        ^


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

                        ~E. W. Dijkstra

                        D 1 Reply Last reply 26 Jan 2021, 14:28
                        0
                        • P Pl45m4
                          26 Jan 2021, 14:18

                          @suslucoder said in Creating a chart with multiple datas:

                          where should i store

                          Do you even read what we wrote?

                          @Pl45m4 said in Creating a chart with multiple datas:

                          Then just call this read function ones for every file you want to read (with the file path as argument)
                          ReadFile(file);

                          Or even make a QStringList with all your filenames and call this function for every element of your list.

                          ^

                          D Offline
                          D Offline
                          deleted286
                          wrote on 26 Jan 2021, 14:28 last edited by
                          #19

                          @Pl45m4 said in

                          Do you even read what we wrote?

                          Of course. I just confused.

                          QString file("/home/ilknur/FourLineChart/Data1.txt");
                          QString file2("/home/ilknur/FourLineChart/Data2.txt");
                          QString file3("/home/ilknur/FourLineChart/Data3.txt");
                          QString file4("/home/ilknur/FourLineChart/Data4.txt");
                          
                          MainWindow::MainWindow(QWidget *parent)
                             : QMainWindow(parent)
                             , ui(new Ui::MainWindow)
                          {
                             ui->setupUi(this);
                             CreateChart();
                             ReadFile(file);
                             ReadFile(file2);
                             ReadFile(file3);
                             ReadFile(file4);
                          
                          
                          
                          void MainWindow::ReadFile(QString file)
                          {
                                 QFile(file);
                          
                                if(file.open(QIODevice::ReadOnly))
                                {
                                    QTextStream in(&file);
                                    while (!in.atEnd()) {
                                        QString line = in.readLine();
                                        QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                        for (const QString &entry : list)
                                        {
                                            double num = entry.toDouble();
                                            qDebug() << num;
                                             // pick correct queue here
                                            queue.enqueue(num);
                                        }
                                    }
                                }
                          }
                          

                          I miss something. But i dont know.

                          J 1 Reply Last reply 26 Jan 2021, 14:34
                          0
                          • D deleted286
                            26 Jan 2021, 14:28

                            @Pl45m4 said in

                            Do you even read what we wrote?

                            Of course. I just confused.

                            QString file("/home/ilknur/FourLineChart/Data1.txt");
                            QString file2("/home/ilknur/FourLineChart/Data2.txt");
                            QString file3("/home/ilknur/FourLineChart/Data3.txt");
                            QString file4("/home/ilknur/FourLineChart/Data4.txt");
                            
                            MainWindow::MainWindow(QWidget *parent)
                               : QMainWindow(parent)
                               , ui(new Ui::MainWindow)
                            {
                               ui->setupUi(this);
                               CreateChart();
                               ReadFile(file);
                               ReadFile(file2);
                               ReadFile(file3);
                               ReadFile(file4);
                            
                            
                            
                            void MainWindow::ReadFile(QString file)
                            {
                                   QFile(file);
                            
                                  if(file.open(QIODevice::ReadOnly))
                                  {
                                      QTextStream in(&file);
                                      while (!in.atEnd()) {
                                          QString line = in.readLine();
                                          QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                          for (const QString &entry : list)
                                          {
                                              double num = entry.toDouble();
                                              qDebug() << num;
                                               // pick correct queue here
                                              queue.enqueue(num);
                                          }
                                      }
                                  }
                            }
                            

                            I miss something. But i dont know.

                            J Offline
                            J Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on 26 Jan 2021, 14:34 last edited by jsulm
                            #20

                            @suslucoder I really don't understand why it is so hard! Please try to figure out such trivial things by yourself.

                            MainWindow::MainWindow(QWidget *parent)
                               : QMainWindow(parent)
                               , ui(new Ui::MainWindow)
                            {
                               ui->setupUi(this);
                               CreateChart();
                               QString file("/home/ilknur/FourLineChart/Data1.txt");
                               QString file2("/home/ilknur/FourLineChart/Data2.txt");
                               QString file3("/home/ilknur/FourLineChart/Data3.txt");
                               QString file4("/home/ilknur/FourLineChart/Data4.txt");
                               ReadFile(file);
                               ReadFile(file2);
                               ReadFile(file3);
                               ReadFile(file4);
                            

                            Or shorter:

                            
                            MainWindow::MainWindow(QWidget *parent)
                               : QMainWindow(parent)
                               , ui(new Ui::MainWindow)
                            {
                               ui->setupUi(this);
                               CreateChart();
                               ReadFile("/home/ilknur/FourLineChart/Data1.txt");
                               ReadFile("/home/ilknur/FourLineChart/Data2.txt");
                               ReadFile("/home/ilknur/FourLineChart/Data3.txt");
                               ReadFile("/home/ilknur/FourLineChart/Data4.txt");
                            

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

                            D 1 Reply Last reply 26 Jan 2021, 14:39
                            0
                            • J jsulm
                              26 Jan 2021, 14:34

                              @suslucoder I really don't understand why it is so hard! Please try to figure out such trivial things by yourself.

                              MainWindow::MainWindow(QWidget *parent)
                                 : QMainWindow(parent)
                                 , ui(new Ui::MainWindow)
                              {
                                 ui->setupUi(this);
                                 CreateChart();
                                 QString file("/home/ilknur/FourLineChart/Data1.txt");
                                 QString file2("/home/ilknur/FourLineChart/Data2.txt");
                                 QString file3("/home/ilknur/FourLineChart/Data3.txt");
                                 QString file4("/home/ilknur/FourLineChart/Data4.txt");
                                 ReadFile(file);
                                 ReadFile(file2);
                                 ReadFile(file3);
                                 ReadFile(file4);
                              

                              Or shorter:

                              
                              MainWindow::MainWindow(QWidget *parent)
                                 : QMainWindow(parent)
                                 , ui(new Ui::MainWindow)
                              {
                                 ui->setupUi(this);
                                 CreateChart();
                                 ReadFile("/home/ilknur/FourLineChart/Data1.txt");
                                 ReadFile("/home/ilknur/FourLineChart/Data2.txt");
                                 ReadFile("/home/ilknur/FourLineChart/Data3.txt");
                                 ReadFile("/home/ilknur/FourLineChart/Data4.txt");
                              
                              D Offline
                              D Offline
                              deleted286
                              wrote on 26 Jan 2021, 14:39 last edited by
                              #21

                              @jsulm said in Creating a chart with multiple datas:

                              MainWindow::MainWindow(QWidget *parent)
                              : QMainWindow(parent)
                              , ui(new Ui::MainWindow)
                              {
                              ui->setupUi(this);
                              CreateChart();
                              ReadFile("/home/ilknur/FourLineChart/Data1.txt");
                              ReadFile("/home/ilknur/FourLineChart/Data2.txt");
                              ReadFile("/home/ilknur/FourLineChart/Data3.txt");
                              ReadFile("/home/ilknur/FourLineChart/Data4.txt");

                              I've do it in that way and i have

                              void MainWindow::ReadFile(QString file)
                              {
                                     QFile(file);
                              
                                     if(file.open(QIODevice::ReadOnly))
                                     {
                                         QTextStream in(&file);
                                         while (!in.atEnd()) {
                                             QString line = in.readLine();
                                             QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                             for (const QString &entry : list)
                                             {
                                                 double num = entry.toDouble();
                                                 qDebug() << num;
                                                  // pick correct queue here
                                                 queue.enqueue(num);
                                             }
                                         }
                                     }
                              }
                              

                              I've got a lot of errors:

                              : In member function ‘void MainWindow::ReadFile(QString)’:
                              : error: declaration of ‘QFile file’ shadows a parameter
                              error: declaration of ‘QFile file’ shadows a parameter
                              QFile(file);
                              ^

                              J 1 Reply Last reply 26 Jan 2021, 14:40
                              0
                              • D deleted286
                                26 Jan 2021, 14:39

                                @jsulm said in Creating a chart with multiple datas:

                                MainWindow::MainWindow(QWidget *parent)
                                : QMainWindow(parent)
                                , ui(new Ui::MainWindow)
                                {
                                ui->setupUi(this);
                                CreateChart();
                                ReadFile("/home/ilknur/FourLineChart/Data1.txt");
                                ReadFile("/home/ilknur/FourLineChart/Data2.txt");
                                ReadFile("/home/ilknur/FourLineChart/Data3.txt");
                                ReadFile("/home/ilknur/FourLineChart/Data4.txt");

                                I've do it in that way and i have

                                void MainWindow::ReadFile(QString file)
                                {
                                       QFile(file);
                                
                                       if(file.open(QIODevice::ReadOnly))
                                       {
                                           QTextStream in(&file);
                                           while (!in.atEnd()) {
                                               QString line = in.readLine();
                                               QStringList list = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
                                               for (const QString &entry : list)
                                               {
                                                   double num = entry.toDouble();
                                                   qDebug() << num;
                                                    // pick correct queue here
                                                   queue.enqueue(num);
                                               }
                                           }
                                       }
                                }
                                

                                I've got a lot of errors:

                                : In member function ‘void MainWindow::ReadFile(QString)’:
                                : error: declaration of ‘QFile file’ shadows a parameter
                                error: declaration of ‘QFile file’ shadows a parameter
                                QFile(file);
                                ^

                                J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 26 Jan 2021, 14:40 last edited by
                                #22

                                @suslucoder said in Creating a chart with multiple datas:

                                QFile(file);

                                Again easy to fix:

                                void MainWindow::ReadFile(QString filePath)
                                {
                                       QFile file(filePath);
                                
                                       if(file.open(QIODevice::ReadOnly))
                                

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

                                D 1 Reply Last reply 26 Jan 2021, 14:42
                                0
                                • J jsulm
                                  26 Jan 2021, 14:40

                                  @suslucoder said in Creating a chart with multiple datas:

                                  QFile(file);

                                  Again easy to fix:

                                  void MainWindow::ReadFile(QString filePath)
                                  {
                                         QFile file(filePath);
                                  
                                         if(file.open(QIODevice::ReadOnly))
                                  
                                  D Offline
                                  D Offline
                                  deleted286
                                  wrote on 26 Jan 2021, 14:42 last edited by
                                  #23

                                  @jsulm okey. We did it in that way. But i have

                                  void MainWindow::Timer_Slot()
                                  {
                                      static float q_x=0;
                                      static float q_x2=0;
                                      static float q_x3=0;
                                      static float q_x4=0;
                                  
                                      if(!queue.isEmpty())
                                          {
                                             double num=queue.dequeue();
                                             q_x += 0.1;
                                             series->append(q_x, num);
                                             chart->scroll(10, 0);
                                             chart->update();
                                             qDebug() << q_x << num;
                                  
                                          }
                                      if(!queue2.isEmpty())
                                          {
                                             double num2=queue2.dequeue();
                                             q_x2 += 0.1;
                                             series2->append(q_x2, num2);
                                             chart->scroll(10, 0);
                                             chart->update();
                                             qDebug() << q_x2 << num2;
                                  
                                  
                                          }
                                      if(!queue3.isEmpty())
                                          {
                                             double num3=queue3.dequeue();
                                             q_x3 += 0.1;
                                             series3->append(q_x3, num3);
                                             chart->scroll(10, 0);
                                             chart->update();
                                          }
                                  
                                      if(!queue4.isEmpty())
                                          {
                                             double num4=queue4.dequeue();
                                             q_x4 += 0.1;
                                             series4->append(q_x4, num4);
                                             chart->scroll(10, 0);
                                             chart->update();
                                          }
                                  }
                                  

                                  What will happen my other queues, in ReadFile() ?

                                  J 1 Reply Last reply 26 Jan 2021, 14:45
                                  0
                                  • D deleted286
                                    26 Jan 2021, 14:42

                                    @jsulm okey. We did it in that way. But i have

                                    void MainWindow::Timer_Slot()
                                    {
                                        static float q_x=0;
                                        static float q_x2=0;
                                        static float q_x3=0;
                                        static float q_x4=0;
                                    
                                        if(!queue.isEmpty())
                                            {
                                               double num=queue.dequeue();
                                               q_x += 0.1;
                                               series->append(q_x, num);
                                               chart->scroll(10, 0);
                                               chart->update();
                                               qDebug() << q_x << num;
                                    
                                            }
                                        if(!queue2.isEmpty())
                                            {
                                               double num2=queue2.dequeue();
                                               q_x2 += 0.1;
                                               series2->append(q_x2, num2);
                                               chart->scroll(10, 0);
                                               chart->update();
                                               qDebug() << q_x2 << num2;
                                    
                                    
                                            }
                                        if(!queue3.isEmpty())
                                            {
                                               double num3=queue3.dequeue();
                                               q_x3 += 0.1;
                                               series3->append(q_x3, num3);
                                               chart->scroll(10, 0);
                                               chart->update();
                                            }
                                    
                                        if(!queue4.isEmpty())
                                            {
                                               double num4=queue4.dequeue();
                                               q_x4 += 0.1;
                                               series4->append(q_x4, num4);
                                               chart->scroll(10, 0);
                                               chart->update();
                                            }
                                    }
                                    

                                    What will happen my other queues, in ReadFile() ?

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 26 Jan 2021, 14:45 last edited by
                                    #24

                                    @suslucoder said in Creating a chart with multiple datas:

                                    What will happen my other queues, in ReadFile() ?

                                    Can't you simply use one queue?
                                    If not then extend the readFile() method:

                                    void MainWindow::ReadFile(const QString &file, QQueue<double> &queue)
                                    {
                                    ...
                                    

                                    And pass queue as second parameter.

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

                                    D 1 Reply Last reply 26 Jan 2021, 14:50
                                    0
                                    • J jsulm
                                      26 Jan 2021, 14:45

                                      @suslucoder said in Creating a chart with multiple datas:

                                      What will happen my other queues, in ReadFile() ?

                                      Can't you simply use one queue?
                                      If not then extend the readFile() method:

                                      void MainWindow::ReadFile(const QString &file, QQueue<double> &queue)
                                      {
                                      ...
                                      

                                      And pass queue as second parameter.

                                      D Offline
                                      D Offline
                                      deleted286
                                      wrote on 26 Jan 2021, 14:50 last edited by
                                      #25

                                      @jsulm said in Creating a chart with multiple datas:

                                      Can't you simply use one queue?

                                      When i use one queue, how can i differ my datas?
                                      Txt files have different values, and i will show all of them in a line chart with different color

                                      J 1 Reply Last reply 26 Jan 2021, 14:52
                                      0
                                      • D deleted286
                                        26 Jan 2021, 14:50

                                        @jsulm said in Creating a chart with multiple datas:

                                        Can't you simply use one queue?

                                        When i use one queue, how can i differ my datas?
                                        Txt files have different values, and i will show all of them in a line chart with different color

                                        J Offline
                                        J Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 26 Jan 2021, 14:52 last edited by jsulm
                                        #26

                                        @suslucoder Then do like I suggested:

                                        void MainWindow::ReadFile(const QString &file, QQueue<double> &queue)
                                        {
                                        ...
                                        }
                                        ...
                                        ReadFile("/home/ilknur/FourLineChart/Data1.txt", queue);
                                        ReadFile("/home/ilknur/FourLineChart/Data2.txt", queue1);
                                        ReadFile("/home/ilknur/FourLineChart/Data3.txt", queue2);
                                        ReadFile("/home/ilknur/FourLineChart/Data4.txt", queue3);
                                        

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

                                        D 1 Reply Last reply 26 Jan 2021, 14:55
                                        1
                                        • J jsulm
                                          26 Jan 2021, 14:52

                                          @suslucoder Then do like I suggested:

                                          void MainWindow::ReadFile(const QString &file, QQueue<double> &queue)
                                          {
                                          ...
                                          }
                                          ...
                                          ReadFile("/home/ilknur/FourLineChart/Data1.txt", queue);
                                          ReadFile("/home/ilknur/FourLineChart/Data2.txt", queue1);
                                          ReadFile("/home/ilknur/FourLineChart/Data3.txt", queue2);
                                          ReadFile("/home/ilknur/FourLineChart/Data4.txt", queue3);
                                          
                                          D Offline
                                          D Offline
                                          deleted286
                                          wrote on 26 Jan 2021, 14:55 last edited by
                                          #27

                                          @jsulm in .h file i have

                                           ```
                                           QQueue<double> queue;
                                           QQueue<double> queue2;
                                           QQueue<double> queue3;
                                           QQueue<double> queue4;
                                          
                                          
                                          Should i delete them?
                                          J 1 Reply Last reply 26 Jan 2021, 14:55
                                          0

                                          17/29

                                          26 Jan 2021, 14:16

                                          • Login

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