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. Array object constructor error
Forum Updated to NodeBB v4.3 + New Features

Array object constructor error

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 678 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.
  • K Offline
    K Offline
    Kycho
    wrote on last edited by Kycho
    #1

    Array object constructor error.
    At runtime, the value of the array is determined,
    I do not know how to solve this problem.

        int setRoom = 9;
        RoomButton *room = new RoomButton[setRoom];  // RoomButton Inheritance QPushButton
        QString roomNum[setRoom];
        roomNum[0] = "201";
        roomNum[1] = "202";
        roomNum[2] = "203";
        roomNum[3] = "205";
        roomNum[4] = "206";
        roomNum[5] = "207";
        roomNum[6] = "208";
        roomNum[7] = "209";
        roomNum[8] = "210";
    
        for(int ii =0; ii<3; ii++){
            for (int i =0; i<3; i++){
                ui->roomSeletGLayout->addWidget(&room[ii*3+i],ii,i); // Good work!
                room[ii*3+i]->setText(roomNum[ii*3+i]); // This is error...T^T
            }
        }
    
    

    Thanks in advance for your help.

    K 1 Reply Last reply
    0
    • K Kycho

      Array object constructor error.
      At runtime, the value of the array is determined,
      I do not know how to solve this problem.

          int setRoom = 9;
          RoomButton *room = new RoomButton[setRoom];  // RoomButton Inheritance QPushButton
          QString roomNum[setRoom];
          roomNum[0] = "201";
          roomNum[1] = "202";
          roomNum[2] = "203";
          roomNum[3] = "205";
          roomNum[4] = "206";
          roomNum[5] = "207";
          roomNum[6] = "208";
          roomNum[7] = "209";
          roomNum[8] = "210";
      
          for(int ii =0; ii<3; ii++){
              for (int i =0; i<3; i++){
                  ui->roomSeletGLayout->addWidget(&room[ii*3+i],ii,i); // Good work!
                  room[ii*3+i]->setText(roomNum[ii*3+i]); // This is error...T^T
              }
          }
      
      

      Thanks in advance for your help.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Kycho

      What is the exact error message?

      Note, dynamic size of arrays as used there requires at least C++ standard of 99 or more. What are your compile settings?

      Vote the answer(s) that helped you to solve your issue(s)

      K 1 Reply Last reply
      0
      • K koahnig

        @Kycho

        What is the exact error message?

        Note, dynamic size of arrays as used there requires at least C++ standard of 99 or more. What are your compile settings?

        K Offline
        K Offline
        Kycho
        wrote on last edited by Kycho
        #3

        @koahnig

        Thank you for your reply.

        Error message is as follows.

        /home/jiminkim/QtProject/SVD110_Tesst/mainwindow.cpp:30: error: base operand of ‘->’ has non-pointer type ‘RoomButton’
                     room[ii*3+i]->setText(roomNum[ii*3+i]); // it is error...T^T
                                 ^~
        
        /home/jiminkim/QtProject/SVD110_Tesst/mainwindow.cpp:30: error: member reference type 'RoomButton' is not a pointer; did you mean to use '.'?
        

        I do not know if C ++ 99 or later is correct....
        But recently installed.
        Using compiler (Linux Ubuntu)
        0_1543312726972_스크린샷, 2018-11-27 18-57-42.png

        K 1 Reply Last reply
        0
        • K Kycho

          @koahnig

          Thank you for your reply.

          Error message is as follows.

          /home/jiminkim/QtProject/SVD110_Tesst/mainwindow.cpp:30: error: base operand of ‘->’ has non-pointer type ‘RoomButton’
                       room[ii*3+i]->setText(roomNum[ii*3+i]); // it is error...T^T
                                   ^~
          
          /home/jiminkim/QtProject/SVD110_Tesst/mainwindow.cpp:30: error: member reference type 'RoomButton' is not a pointer; did you mean to use '.'?
          

          I do not know if C ++ 99 or later is correct....
          But recently installed.
          Using compiler (Linux Ubuntu)
          0_1543312726972_스크린샷, 2018-11-27 18-57-42.png

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Kycho

          You would need a CONFIG settings like

          CONFIG += c++11
          

          for C++11 standard. Depending on your actual compiler version this might be already default.

          The syntax of

           RoomButton *room = new RoomButton[setRoom]; 
          

          is wrong for you try to do. It should be more like

           RoomButton *room[setRoom];
          for ( int i = 0; i < setRoom; ++i )
              RoomButton[i]= new RoomButton; 
          

          However, I recommend using a container such as std::vector or QVector for handling this.

          Note: above source is brain to keyboard not tested.

          Vote the answer(s) that helped you to solve your issue(s)

          K 1 Reply Last reply
          4
          • K koahnig

            @Kycho

            You would need a CONFIG settings like

            CONFIG += c++11
            

            for C++11 standard. Depending on your actual compiler version this might be already default.

            The syntax of

             RoomButton *room = new RoomButton[setRoom]; 
            

            is wrong for you try to do. It should be more like

             RoomButton *room[setRoom];
            for ( int i = 0; i < setRoom; ++i )
                RoomButton[i]= new RoomButton; 
            

            However, I recommend using a container such as std::vector or QVector for handling this.

            Note: above source is brain to keyboard not tested.

            K Offline
            K Offline
            Kycho
            wrote on last edited by
            #5

            @koahnig

            Thank you!!!!!!!!!!!!!!!!!!

            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