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. problem with scope of array??

problem with scope of array??

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 5 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.
  • TheCipo76T Offline
    TheCipo76T Offline
    TheCipo76
    wrote on last edited by TheCipo76
    #1

    Hi,
    i'm new with c++ and Qt both..
    i've created a form then dinamically create and populate some array..

    0_1537604015979_Schermata 2018-09-22 alle 10.10.09.png

    my problem is that when you press on pushbutton "CALCOLA" i've to manage the data loaded dinamically in the array..

    the array was created with this code:

    QLineEdit *array_Fine15[5];
        for (int i = 0; i<5; i++)
        {
            array_Fine15[i] = new QLineEdit;
            ui->gridLayout_2->addWidget(array_Fine15[i]);
            array_Fine15[i]->setFixedWidth(75);
            array_Fine15[i]->setFixedHeight(24);
            array_Fine15[i]->setText("12.00");
        }
    

    this code:

    0_1537604278358_Schermata 2018-09-22 alle 10.17.13.png

    give my this error:

    no member named 'array_PezziProd' in 'QGridLayout'

    i think was a scope problem but i havn't idea how to solve it.

    can anyone help me please?

    JonBJ 1 Reply Last reply
    0
    • TheCipo76T TheCipo76

      Hi,
      i'm new with c++ and Qt both..
      i've created a form then dinamically create and populate some array..

      0_1537604015979_Schermata 2018-09-22 alle 10.10.09.png

      my problem is that when you press on pushbutton "CALCOLA" i've to manage the data loaded dinamically in the array..

      the array was created with this code:

      QLineEdit *array_Fine15[5];
          for (int i = 0; i<5; i++)
          {
              array_Fine15[i] = new QLineEdit;
              ui->gridLayout_2->addWidget(array_Fine15[i]);
              array_Fine15[i]->setFixedWidth(75);
              array_Fine15[i]->setFixedHeight(24);
              array_Fine15[i]->setText("12.00");
          }
      

      this code:

      0_1537604278358_Schermata 2018-09-22 alle 10.17.13.png

      give my this error:

      no member named 'array_PezziProd' in 'QGridLayout'

      i think was a scope problem but i havn't idea how to solve it.

      can anyone help me please?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @TheCipo76
      It's difficult to figure from what you have presented as your code:

      • QLineEdit *array_Fine15[5];
        Is that declaration of an array local to a function (in which case it does not exist once the function has exited) or is that a member variable of a class (in which case it exists as long as an instance of the class exists)?

      After executing that loop, regardless of whether the array itself has or has not gone out of scope, you have created 5 QLineEdits which have been added into ui->gridLayout_2. These line edits do not have their own variables associated with them, but they still exist, e.g. if you searched the widgets on ui->gridLayout_2 they would still be there.

      • ->array_PezziProd[i]
        It's red underlined, indicating it simply does not exist. There is no mention elsewhere in your code of this variable, so where is this declared as a member of the QGridLayout instance which is ui->gridLyout_5? If you think there is any relationship between your array_Fine15 and array_PezziProd, there is not.

      Suggestion: first get your code compiling & working with one line edit, no array. Then start moving it over to allow for an array.

      P.S.
      When posting code, please do not paste an image of code as you have done. It makes it very difficult for anyone trying to comment on it. Always paste code as text into your emails. Put 3 backticks (` character above Tab key on my UK keyboard) before the first line and again after the last line around the code.

      1 Reply Last reply
      2
      • TheCipo76T Offline
        TheCipo76T Offline
        TheCipo76
        wrote on last edited by TheCipo76
        #3

        the arrays was created with code on form load

        ui->setupUi(this);
        
        ... create arrays and add it to general layout
        

        when i lauch application and click on pushbutton (slot / event)

        don't find the array (added as you see in the gridLayout)

        and give me the up-posted error..

        can i solve with associated variables? and how i have to do in this case?

        JonBJ 1 Reply Last reply
        0
        • TheCipo76T TheCipo76

          the arrays was created with code on form load

          ui->setupUi(this);
          
          ... create arrays and add it to general layout
          

          when i lauch application and click on pushbutton (slot / event)

          don't find the array (added as you see in the gridLayout)

          and give me the up-posted error..

          can i solve with associated variables? and how i have to do in this case?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @TheCipo76
          Probably then make the array variable be a member of your "form", then it will stay in scope.

          TheCipo76T 1 Reply Last reply
          0
          • JonBJ JonB

            @TheCipo76
            Probably then make the array variable be a member of your "form", then it will stay in scope.

            TheCipo76T Offline
            TheCipo76T Offline
            TheCipo76
            wrote on last edited by
            #5

            @JonB i have no idea how to do it..

            can you put here an exampe please?

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

              Hi,

              Best to read about them here.

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

              TheCipo76T JonBJ 2 Replies Last reply
              2
              • SGaistS SGaist

                Hi,

                Best to read about them here.

                TheCipo76T Offline
                TheCipo76T Offline
                TheCipo76
                wrote on last edited by
                #7

                @SGaist
                Ok, now i've understand how to do it.
                Thank you very much

                1 Reply Last reply
                1
                • SGaistS SGaist

                  Hi,

                  Best to read about them here.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @SGaist said in problem with scope of array??:

                  Hi,

                  Best to read about them here.

                  How come you give him one dense reference to read and it turns out to be just the right one to explain to his satisfaction?!

                  aha_1980A 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @SGaist said in problem with scope of array??:

                    Hi,

                    Best to read about them here.

                    How come you give him one dense reference to read and it turns out to be just the right one to explain to his satisfaction?!

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @JonB ... it was the right reference ;)

                    Qt has to stay free or it will die.

                    1 Reply Last reply
                    1
                    • TheCipo76T Offline
                      TheCipo76T Offline
                      TheCipo76
                      wrote on last edited by
                      #10

                      Ok i read the link documentation but i can't do this work..

                      i think that i have to create a class with QLabelEdit array

                      so i can manage data in or out the main with no scope problem.

                      It is correct?

                      If yes..

                      i've view some tutorial in order to learn c++ ( i'm coming from VB6)
                      but this is too complicate for me..

                      anyone can put a example?

                      jsulmJ 1 Reply Last reply
                      0
                      • TheCipo76T TheCipo76

                        Ok i read the link documentation but i can't do this work..

                        i think that i have to create a class with QLabelEdit array

                        so i can manage data in or out the main with no scope problem.

                        It is correct?

                        If yes..

                        i've view some tutorial in order to learn c++ ( i'm coming from VB6)
                        but this is too complicate for me..

                        anyone can put a example?

                        jsulmJ Online
                        jsulmJ Online
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by jsulm
                        #11

                        @TheCipo76 Simply put these arrays as member variables of your form class, there is no need for an extra class just for these arrays.

                        class regtemciclo: public...
                        {
                        ...
                        private:
                            QLineEdit *array_Fine15[5];
                        ...
                        }
                        

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

                        TheCipo76T 1 Reply Last reply
                        1
                        • jsulmJ jsulm

                          @TheCipo76 Simply put these arrays as member variables of your form class, there is no need for an extra class just for these arrays.

                          class regtemciclo: public...
                          {
                          ...
                          private:
                              QLineEdit *array_Fine15[5];
                          ...
                          }
                          
                          TheCipo76T Offline
                          TheCipo76T Offline
                          TheCipo76
                          wrote on last edited by
                          #12

                          @jsulm Eureka! it works..

                          thank you very much!

                          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