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 becoming null
Qt 6.11 is out! See what's new in the release blog

Array becoming null

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 798 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.
  • S Offline
    S Offline
    shreya_agrawal
    wrote on last edited by
    #1

    I am creating some push buttons (say valves) and adding them in an array and then displaying them in a grid layout. When I move to the next page, I delete the current array and then repopulate it. But when I am trying to access it, it is becoming a nullpointer. So, basically the valves are visible on the next page, but I am unable to access them. What would be the solution for it?

    J.HilkJ 1 Reply Last reply
    0
    • S shreya_agrawal

      I am creating some push buttons (say valves) and adding them in an array and then displaying them in a grid layout. When I move to the next page, I delete the current array and then repopulate it. But when I am trying to access it, it is becoming a nullpointer. So, basically the valves are visible on the next page, but I am unable to access them. What would be the solution for it?

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @shreya_agrawal said in Array becoming null:

      What would be the solution for it

      Don't delete the array in the first place ?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      S 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        @shreya_agrawal said in Array becoming null:

        What would be the solution for it

        Don't delete the array in the first place ?

        S Offline
        S Offline
        shreya_agrawal
        wrote on last edited by
        #3

        @J-Hilk
        But without deleting the current array, how would I be able to display the new array when I click the next and previous buttons?

        J.HilkJ 1 Reply Last reply
        0
        • S shreya_agrawal

          @J-Hilk
          But without deleting the current array, how would I be able to display the new array when I click the next and previous buttons?

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @shreya_agrawal I don't know. I can't give you more, due to a severe lack of information from your part.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          S 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @shreya_agrawal I don't know. I can't give you more, due to a severe lack of information from your part.

            S Offline
            S Offline
            shreya_agrawal
            wrote on last edited by
            #5

            @J-Hilk
            I think the problem is deleting the array every time the next or previous button is clicked. I am thinking of adding all valves to the list in the beginning and then showing and hiding them according to the indexes, which will be changed when the previous or next buttons are clicked. I hope I am able to put forward my issue clearly this time.

            S 2 Replies Last reply
            0
            • S shreya_agrawal has marked this topic as solved on
            • S shreya_agrawal

              @J-Hilk
              I think the problem is deleting the array every time the next or previous button is clicked. I am thinking of adding all valves to the list in the beginning and then showing and hiding them according to the indexes, which will be changed when the previous or next buttons are clicked. I hope I am able to put forward my issue clearly this time.

              S Offline
              S Offline
              shreya_agrawal
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • S shreya_agrawal

                @J-Hilk
                I think the problem is deleting the array every time the next or previous button is clicked. I am thinking of adding all valves to the list in the beginning and then showing and hiding them according to the indexes, which will be changed when the previous or next buttons are clicked. I hope I am able to put forward my issue clearly this time.

                S Offline
                S Offline
                shreya_agrawal
                wrote on last edited by
                #7

                @shreya_agrawal
                This is how I did it for future reference:

                // First, add all valves to the array
                for (int i = 0; i < totalValves; ++i)
                {
                    valve[i] = new Valve(this);
                }
                
                // Show or hide the valves according to their indexes
                for (int i = 0; i < totalValves; ++i)
                {
                    if (valve[i] != nullptr)
                    {
                        if (i >= currentIndex && i < currentIndex + visibleValves) 
                        {
                            valve[i]->show();
                        }
                        else 
                        {
                            valve[i]->hide();
                        }
                }
                
                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