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. Connecting Qt to data generated by formulas
QtWS25 Last Chance

Connecting Qt to data generated by formulas

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.7k 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.
  • R Offline
    R Offline
    Robert M. Koretsky
    wrote on last edited by Robert M. Koretsky
    #1

    If I have some C++ formulas that generate numbers as values, how do I get that into Qt so that it can put the values into Qt graphics?
    In other words, how do you hook numerical values to QT so that you can get graphics to be displayed, either in dialog boxes or anything Qt is capable of showing as graphics?
    Not talking about here about spreadsheet or database values, but numerical values generated by either simple or complex formulas. The way I see it, a traditional graphics-capable program has two parts: a part that generates the values, and a part that displays the values as some kind of picture. How is Qt different from this? Some traditional graphics programs write the data to files, and then the graphics portion opens the files, and displays the data. Can Qt do this?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      From your description I feel you need some data visualisation classes. Can you check QtCharts ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      R 1 Reply Last reply
      7
      • dheerendraD dheerendra

        From your description I feel you need some data visualisation classes. Can you check QtCharts ?

        R Offline
        R Offline
        Robert M. Koretsky
        wrote on last edited by Robert M. Koretsky
        #3

        Thanks for this considerate and most excellent reply!
        @dheerendra surely you mean Qt classes, I'm a newbie at Qt but not at connecting data to graphics. I'll look at the Qt facility you suggest. Just an observation here, available beginner docs don't get to your suggested facility as far as I can see.

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi and welcome to the forum
          There are many ways to both input data and show/draw/plot on the screen.
          Qt is for programming and it can read and display data, any way you program it. :)

          For reading data from file, you could use QFile. http://doc.qt.io/qt-5/qfile.html

          Example:

          int GetBarHeight(int MAX) {
            return rand() % (MAX - 5) + 5;
          }
          
          void MainWindow::on_pushButton_released() {
          
            int h = ui->label->height();
            int w = ui->label->width();
          
            QPixmap pix(w, h);
            QPainter paint(&pix);
            pix.fill( Qt::white );
            paint.setPen(QColor(0, 0, 0, 255));
          
          
            int y = 0;
            int x = 0;
          
            int bw = 10; // bar width
            for (int barcount = 0; barcount < 12; ++barcount) {
              paint.setBrush(QColor(255 - x, 34 + x, 255, 255));
              paint.drawRect(x, h - GetBarHeight(h),  bw, h );
              x += bw + 4;
            }
            paint.end();
            ui->label->setPixmap(pix);
          }
          
          

          Gives this:
          alt text

          this is super poor mans graph. for anything serious, use
          http://www.qcustomplot.com/
          or Qtchart

          If you just want to draw on screen then QPainter is the one to read docs on.

          R 1 Reply Last reply
          2
          • mrjjM mrjj

            Hi and welcome to the forum
            There are many ways to both input data and show/draw/plot on the screen.
            Qt is for programming and it can read and display data, any way you program it. :)

            For reading data from file, you could use QFile. http://doc.qt.io/qt-5/qfile.html

            Example:

            int GetBarHeight(int MAX) {
              return rand() % (MAX - 5) + 5;
            }
            
            void MainWindow::on_pushButton_released() {
            
              int h = ui->label->height();
              int w = ui->label->width();
            
              QPixmap pix(w, h);
              QPainter paint(&pix);
              pix.fill( Qt::white );
              paint.setPen(QColor(0, 0, 0, 255));
            
            
              int y = 0;
              int x = 0;
            
              int bw = 10; // bar width
              for (int barcount = 0; barcount < 12; ++barcount) {
                paint.setBrush(QColor(255 - x, 34 + x, 255, 255));
                paint.drawRect(x, h - GetBarHeight(h),  bw, h );
                x += bw + 4;
              }
              paint.end();
              ui->label->setPixmap(pix);
            }
            
            

            Gives this:
            alt text

            this is super poor mans graph. for anything serious, use
            http://www.qcustomplot.com/
            or Qtchart

            If you just want to draw on screen then QPainter is the one to read docs on.

            R Offline
            R Offline
            Robert M. Koretsky
            wrote on last edited by
            #5

            @mrjj much thanks for this excellent repy! On first glance, it appears to me that reading the data from a file (which perhaps was generated by some module that contained assignment statements using simple or complex formulae) and "displaying" it as Qt graphics are exactly as I said in my initial question: two totally separate components. This is as I found it in Xlib and Xcb programing in C. So in your reply, you have given me a link to help on file operations, and then a demonstration example of how Qt does graphics- both, on the surface at least, with their code unrelated. That's fine. It is the linking of the two components, or as I prefer to think of it, the "hooking" of the output of the assignment statement module (difficult for me to not think in terms of modular programs!) to the Qt graphical component, that is of concern to me. Even in the QtCharts signature example that Dheerendra steered me to in his most excellent reply,
            http://doc.qt.io/qt-5/qtcharts-linechart-main-cpp.html
            those two components are clearly there, but not auspiciously delineated.
            I'm browsing through the on-line Qt docs, and some introductory books, such as "C++ GUI Programming with Qt 4, Second Edition by Jasmin Blanchette; Mark Summerfield", and there appears to be little beginner information that addresses my question.
            Thanks again for your considerate and excellent reply!
            Sincerely,
            Robert M. Koretsky

            kshegunovK 1 Reply Last reply
            2
            • R Robert M. Koretsky

              @mrjj much thanks for this excellent repy! On first glance, it appears to me that reading the data from a file (which perhaps was generated by some module that contained assignment statements using simple or complex formulae) and "displaying" it as Qt graphics are exactly as I said in my initial question: two totally separate components. This is as I found it in Xlib and Xcb programing in C. So in your reply, you have given me a link to help on file operations, and then a demonstration example of how Qt does graphics- both, on the surface at least, with their code unrelated. That's fine. It is the linking of the two components, or as I prefer to think of it, the "hooking" of the output of the assignment statement module (difficult for me to not think in terms of modular programs!) to the Qt graphical component, that is of concern to me. Even in the QtCharts signature example that Dheerendra steered me to in his most excellent reply,
              http://doc.qt.io/qt-5/qtcharts-linechart-main-cpp.html
              those two components are clearly there, but not auspiciously delineated.
              I'm browsing through the on-line Qt docs, and some introductory books, such as "C++ GUI Programming with Qt 4, Second Edition by Jasmin Blanchette; Mark Summerfield", and there appears to be little beginner information that addresses my question.
              Thanks again for your considerate and excellent reply!
              Sincerely,
              Robert M. Koretsky

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @Robert-M.-Koretsky said in Connecting Qt to data generated by formulas:

              It is the linking of the two components, or as I prefer to think of it, the "hooking" of the output of the assignment statement module (difficult for me to not think in terms of modular programs!) to the Qt graphical component, that is of concern to me.

              That's what signals and slots are for. But as any C++ program (or C program for that matter) there's always controller code that knows about both modules/classes or w/e you want to call them. The "auspicious delineation", as you so eloquently have put it, is up to the person writing the code. Qt only provides tools to do so, there's no ready out-of-the-box just-plug-and-play solution.

              Read and abide by the Qt Code of Conduct

              R 1 Reply Last reply
              1
              • kshegunovK kshegunov

                @Robert-M.-Koretsky said in Connecting Qt to data generated by formulas:

                It is the linking of the two components, or as I prefer to think of it, the "hooking" of the output of the assignment statement module (difficult for me to not think in terms of modular programs!) to the Qt graphical component, that is of concern to me.

                That's what signals and slots are for. But as any C++ program (or C program for that matter) there's always controller code that knows about both modules/classes or w/e you want to call them. The "auspicious delineation", as you so eloquently have put it, is up to the person writing the code. Qt only provides tools to do so, there's no ready out-of-the-box just-plug-and-play solution.

                R Offline
                R Offline
                Robert M. Koretsky
                wrote on last edited by
                #7

                @kshegunov I think everyone interested in this post should look at the primary examples of QCustomPlot. In his examples, he clearly delineates what code is generating the numbers, and what Qt graphics are displaying it.

                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