Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Array - for storing the first value in Qt C++
Forum Update on Monday, May 27th 2025

Array - for storing the first value in Qt C++

Scheduled Pinned Locked Moved Solved C++ Gurus
8 Posts 4 Posters 2.4k 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.
  • JerwinprabuJ Offline
    JerwinprabuJ Offline
    Jerwinprabu
    wrote on last edited by
    #1

    I have written a Qt C++ code for my project. I am having trouble storing values in arrays. I have written a code for measuring the value from hardware. For storing first value I have used Array, that is working fine. For example when the program get started, I got initial value lets say 53.6854.

    Now I want to take this value into another void for comparing with other values. So according to first value, I am going to check remaining values. I can't fix the constant value because Initial value will change every time.

    I want to take that first value to void Motion::Synchronization(QString motiontype) else if(type == 2)

    Then according to stored first value I will check remaining value. If that is not equal to that value I will create the other logic to reach that position. For that I need first value. I don't know how to change, or else any other ways to get the first value ? Assist me to solve this issue.

    void check(float a)
    {
        std::cout << a << std::endl;
    }
    
    
    void Motion::Synchronization(QString type)
    {
      if(type == 1){
     }
     else if(type == 2)
    {
      delay(20);
      }
    }
    
    void Motion::slow()
    {
        float n[ ] = {Thread::data};
        check(n[0]);
    }
    
    jsulmJ 2 Replies Last reply
    0
    • JerwinprabuJ Jerwinprabu

      I have written a Qt C++ code for my project. I am having trouble storing values in arrays. I have written a code for measuring the value from hardware. For storing first value I have used Array, that is working fine. For example when the program get started, I got initial value lets say 53.6854.

      Now I want to take this value into another void for comparing with other values. So according to first value, I am going to check remaining values. I can't fix the constant value because Initial value will change every time.

      I want to take that first value to void Motion::Synchronization(QString motiontype) else if(type == 2)

      Then according to stored first value I will check remaining value. If that is not equal to that value I will create the other logic to reach that position. For that I need first value. I don't know how to change, or else any other ways to get the first value ? Assist me to solve this issue.

      void check(float a)
      {
          std::cout << a << std::endl;
      }
      
      
      void Motion::Synchronization(QString type)
      {
        if(type == 1){
       }
       else if(type == 2)
      {
        delay(20);
        }
      }
      
      void Motion::slow()
      {
          float n[ ] = {Thread::data};
          check(n[0]);
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Jerwinprabu I don't understand the problem: you get the first value from an array using 0 as index as you do already:

      check(n[0]);
      

      So, what is the problem?

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

      1 Reply Last reply
      1
      • JerwinprabuJ Jerwinprabu

        I have written a Qt C++ code for my project. I am having trouble storing values in arrays. I have written a code for measuring the value from hardware. For storing first value I have used Array, that is working fine. For example when the program get started, I got initial value lets say 53.6854.

        Now I want to take this value into another void for comparing with other values. So according to first value, I am going to check remaining values. I can't fix the constant value because Initial value will change every time.

        I want to take that first value to void Motion::Synchronization(QString motiontype) else if(type == 2)

        Then according to stored first value I will check remaining value. If that is not equal to that value I will create the other logic to reach that position. For that I need first value. I don't know how to change, or else any other ways to get the first value ? Assist me to solve this issue.

        void check(float a)
        {
            std::cout << a << std::endl;
        }
        
        
        void Motion::Synchronization(QString type)
        {
          if(type == 1){
         }
         else if(type == 2)
        {
          delay(20);
          }
        }
        
        void Motion::slow()
        {
            float n[ ] = {Thread::data};
            check(n[0]);
        }
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Jerwinprabu I moved your question to "C++ Gurus" forum as it isn't related to Qt but to C++.

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

        1 Reply Last reply
        2
        • JerwinprabuJ Offline
          JerwinprabuJ Offline
          Jerwinprabu
          wrote on last edited by
          #4

          @jsulm How can I take that stored value from Here

          void Motion::slow()
          {
              float n[ ] = {Thread::data};
              check(n[0]);
          }
          

          to

          else if(type == 2)
          {
           delay(20);
           }
          
          D 1 Reply Last reply
          0
          • JerwinprabuJ Jerwinprabu

            @jsulm How can I take that stored value from Here

            void Motion::slow()
            {
                float n[ ] = {Thread::data};
                check(n[0]);
            }
            

            to

            else if(type == 2)
            {
             delay(20);
             }
            
            D Offline
            D Offline
            Daniil Chernyshev
            wrote on last edited by
            #5

            @Jerwinprabu Not sure if I fully understand your problem, but why can't you create a local class variable for the value you need?

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

              Hi,

              To add to @Daniil-Chernyshev, why are you creating an array of one element to immediately take the first element ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              JerwinprabuJ 1 Reply Last reply
              1
              • SGaistS SGaist

                Hi,

                To add to @Daniil-Chernyshev, why are you creating an array of one element to immediately take the first element ?

                JerwinprabuJ Offline
                JerwinprabuJ Offline
                Jerwinprabu
                wrote on last edited by
                #7

                @SGaist Ya exactly. It's not required to create Array. Simply store the first value, and taken the first value to next function. Ya, problem solved.

                1 Reply Last reply
                0
                • D Daniil Chernyshev

                  @Jerwinprabu Not sure if I fully understand your problem, but why can't you create a local class variable for the value you need?

                  JerwinprabuJ Offline
                  JerwinprabuJ Offline
                  Jerwinprabu
                  wrote on last edited by
                  #8

                  @Daniil-Chernyshev Because Each and every time value will update from hardware, so for every 5 milli second will get new value. In that same thread only I need first value and real time value.

                  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