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??
Forum Updated to NodeBB v4.3 + New Features

problem with scope of array??

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 5 Posters 1.7k 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.
  • T Offline
    T Offline
    TheCipo76
    wrote on 22 Sept 2018, 08:19 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?

    J 1 Reply Last reply 22 Sept 2018, 08:45
    0
    • T TheCipo76
      22 Sept 2018, 08:19

      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?

      J Offline
      J Offline
      JonB
      wrote on 22 Sept 2018, 08:45 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
      • T Offline
        T Offline
        TheCipo76
        wrote on 22 Sept 2018, 09:04 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?

        J 1 Reply Last reply 22 Sept 2018, 09:12
        0
        • T TheCipo76
          22 Sept 2018, 09:04

          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?

          J Offline
          J Offline
          JonB
          wrote on 22 Sept 2018, 09:12 last edited by
          #4

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

          T 1 Reply Last reply 22 Sept 2018, 09:14
          0
          • J JonB
            22 Sept 2018, 09:12

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

            T Offline
            T Offline
            TheCipo76
            wrote on 22 Sept 2018, 09:14 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 22 Sept 2018, 20:35 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

              T J 2 Replies Last reply 23 Sept 2018, 09:22
              2
              • S SGaist
                22 Sept 2018, 20:35

                Hi,

                Best to read about them here.

                T Offline
                T Offline
                TheCipo76
                wrote on 23 Sept 2018, 09:22 last edited by
                #7

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

                1 Reply Last reply
                1
                • S SGaist
                  22 Sept 2018, 20:35

                  Hi,

                  Best to read about them here.

                  J Offline
                  J Offline
                  JonB
                  wrote on 23 Sept 2018, 18:15 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?!

                  A 1 Reply Last reply 23 Sept 2018, 19:11
                  0
                  • J JonB
                    23 Sept 2018, 18:15

                    @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?!

                    A Offline
                    A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on 23 Sept 2018, 19:11 last edited by
                    #9

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

                    Qt has to stay free or it will die.

                    1 Reply Last reply
                    1
                    • T Offline
                      T Offline
                      TheCipo76
                      wrote on 24 Sept 2018, 13:07 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?

                      J 1 Reply Last reply 25 Sept 2018, 05:19
                      0
                      • T TheCipo76
                        24 Sept 2018, 13:07

                        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?

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 25 Sept 2018, 05:19 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

                        T 1 Reply Last reply 25 Sept 2018, 12:52
                        1
                        • J jsulm
                          25 Sept 2018, 05:19

                          @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];
                          ...
                          }
                          
                          T Offline
                          T Offline
                          TheCipo76
                          wrote on 25 Sept 2018, 12:52 last edited by
                          #12

                          @jsulm Eureka! it works..

                          thank you very much!

                          1 Reply Last reply
                          0

                          5/12

                          22 Sept 2018, 09:14

                          • Login

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