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. Little help with a project
Forum Updated to NodeBB v4.3 + New Features

Little help with a project

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

    Hello guys. I'm Brazilian and I'm learning QT. I want to make a simple project, but I'm having trouble developing the code. The idea is to create a method that does a sin (sin () math function) that receives as a parameter another method that increments from 1 to -1, with steps of 0.1. The first method will output an array that I would use to fill a chart. Someone help me? please..

    VRoninV 1 Reply Last reply
    0
    • F FelpsGK

      Hello guys. I'm Brazilian and I'm learning QT. I want to make a simple project, but I'm having trouble developing the code. The idea is to create a method that does a sin (sin () math function) that receives as a parameter another method that increments from 1 to -1, with steps of 0.1. The first method will output an array that I would use to fill a chart. Someone help me? please..

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @FelpsGK said in Little help with a project:

      The idea is to create a method that does a sin (sin () math function)

      std::sin

      that increments from 1 to -1, with steps of 0.1

      for(double i = 1.0; i>=-1.0; i-=0.1)

      The first method will output an array

      QVector<double> array;
      array.reserve(20);
      for(double i = 1.0; i>=-1.0; i-=0.1)
      array << std::sin(i);
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • F Offline
        F Offline
        FelpsGK
        wrote on last edited by FelpsGK
        #3

        @VRonin I think I said it wrong. As a method, I mentioned the function. Something like "public void ....". I usually program in java, so I'm used to calling everything by method. But I understood logic. The question would be, how to fill a graph with this array? Make the graph receive the data and auto-fill it from the received array.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          As a method, I mentioned the function.

          std::sin is already a function. I don't see the advantage of having a function doing what a for loop does

          From https://doc.qt.io/qt-5/qtcharts-linechart-example.html

          #include <QtWidgets/QApplication>
          #include <QtWidgets/QMainWindow>
          #include <QtCharts/QChartView>
          #include <QtCharts/QLineSeries>
          
          QT_CHARTS_USE_NAMESPACE
          
          int main(int argc, char *argv[])
          {
              QApplication a(argc, argv);
          const double doublePi = 2.0*std::acos(-1);
              QLineSeries *series = new QLineSeries();
          for(double i = 0; i>=doublePi ; i+=0.1)
          series->append(i,  std::sin(i););
          
              QChart *chart = new QChart();
              chart->legend()->hide();
              chart->addSeries(series);
              chart->createDefaultAxes();
              chart->setTitle("Sin chart example");
          
              QChartView *chartView = new QChartView(chart);
              chartView->setRenderHint(QPainter::Antialiasing);
          
              QMainWindow window;
              window.setCentralWidget(chartView);
              window.resize(400, 300);
              window.show();
          
              return a.exec();
          }
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          F 1 Reply Last reply
          4
          • VRoninV VRonin

            As a method, I mentioned the function.

            std::sin is already a function. I don't see the advantage of having a function doing what a for loop does

            From https://doc.qt.io/qt-5/qtcharts-linechart-example.html

            #include <QtWidgets/QApplication>
            #include <QtWidgets/QMainWindow>
            #include <QtCharts/QChartView>
            #include <QtCharts/QLineSeries>
            
            QT_CHARTS_USE_NAMESPACE
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
            const double doublePi = 2.0*std::acos(-1);
                QLineSeries *series = new QLineSeries();
            for(double i = 0; i>=doublePi ; i+=0.1)
            series->append(i,  std::sin(i););
            
                QChart *chart = new QChart();
                chart->legend()->hide();
                chart->addSeries(series);
                chart->createDefaultAxes();
                chart->setTitle("Sin chart example");
            
                QChartView *chartView = new QChartView(chart);
                chartView->setRenderHint(QPainter::Antialiasing);
            
                QMainWindow window;
                window.setCentralWidget(chartView);
                window.resize(400, 300);
                window.show();
            
                return a.exec();
            }
            
            F Offline
            F Offline
            FelpsGK
            wrote on last edited by
            #5

            @VRonin
            I'm very lazy and slow on this. So one last question: If I copy this code there in my respective class, it already works? Or am I going to need to do something?

            1 Reply Last reply
            -1
            • F Offline
              F Offline
              FelpsGK
              wrote on last edited by
              #6

              The graph is showing nothing

              1 Reply Last reply
              0
              • 6thC6 Offline
                6thC6 Offline
                6thC
                wrote on last edited by
                #7

                Kinda comes across as "do my job for me".
                You are a developer, it's your job to read the documentation on Charts if you want charts... at least try.

                https://doc.qt.io/qt-5.9/qtcharts-index.html

                To link against the Qt Charts module, add this line to your qmake project file:
                QT += charts

                I cannot find a reference to but seem to remember also needing:
                widgets
                Maybe because I use ChartView's? Dunno.

                QT_CHARTS_USE_NAMESPACE
                is a macro and does the same as this, I can't really remember, but again, the docs say and how I now use is as per docs:

                If you intend to use Qt Charts C++ classes in your application, use the following include and using directives:
                #include <QtCharts>
                using namespace QtCharts;

                You won't (or shouldn't imo) get far being that kind of lazy. Nobody appreciates carrying another developer, we have enough to do already.

                1 Reply Last reply
                4

                • Login

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