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. QGriddlayout works for grid 80*80 but not for 100*100 or more (SIGSEGV error)
Qt 6.11 is out! See what's new in the release blog

QGriddlayout works for grid 80*80 but not for 100*100 or more (SIGSEGV error)

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 8 Posters 3.6k Views 3 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.
  • nageshN Offline
    nageshN Offline
    nagesh
    wrote on last edited by
    #7

    @Davay confirm that as you increase the grid from 80x80 to 100x100, the following index access from the matrix is valid?

    (*this)(r,c).getState()
    (*this)(r,c).getMaterial()
    (*this)(r,c).getBurningTime()

    My guess is that matrix is being initialized to 80x80

    D 1 Reply Last reply
    0
    • nageshN nagesh

      @Davay confirm that as you increase the grid from 80x80 to 100x100, the following index access from the matrix is valid?

      (*this)(r,c).getState()
      (*this)(r,c).getMaterial()
      (*this)(r,c).getBurningTime()

      My guess is that matrix is being initialized to 80x80

      D Offline
      D Offline
      Davay
      wrote on last edited by
      #8

      @nagesh Thank you for your comment, all of them seem to be initialized. I also checked for hard coding errors several times but don't seem to find any of that sort sadly.

      1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Davay said in QGriddlayout works for grid 80*80 but not for 100*100 or more (SIGSEGV error):

        Can you elaborate why it would lead to problems

        You call the eventloop but it's not run in the 'outer' loop. So basically you have

        outer main eventloop -> your program logic -> inner event loop

        but this can lead to problems, especially when your program logic was called as a result of a queued signal/slot connection. When you then call the eventloop inside this slot, the signal may be evaluated again since it's not yet finished. Also the order of the signals can be mixed up due to this and other stuff which is very hard to debug. Therefore avoid it, especially when you try to delay something. Qt is event driven and you should not do such things.

        and why to problems only occur for big enough grids?

        timing or others, no idea but what you're doing is not recommended.

        D Offline
        D Offline
        Davay
        wrote on last edited by
        #9

        @Christian-Ehrlicher Thank you for the elaboration! I've followed your advice and it did help me with some laggy issues of my program but sadly not with the grid. I've changed my delay function in:

        QTimer ts;
        ts.start(200);
        QEventLoop loop;
        QObject::connect(&ts, SIGNAL(timeout()), &loop, SLOT(quit()));
        loop.exec();
        
        1 Reply Last reply
        0
        • D Davay

          Sorry in advance I am very new to QT and c++. I am trying to make a grid filled with colored clickable labels. And the whole program works perfectly for grids the size smaller than 80*80 but for bigger gridds I get a SIGSEGV segmentation fault error in the debugger, it doesn't exactly tell my why. This is the code where the error most likely originates:

          void Gridd::ShowStart(QWidget *wid){
          
              QGridLayout *layout = new QGridLayout;
          
              for (unsigned int r = 0; r < rows; r++) { 
                  for (unsigned int c = 0; c < cols; c++) {
          
                      ClickableLabel  *label = new ClickableLabel(r,c); 
                      QString str = " background-color : " ;
          
                      if ((*this)(r,c).getState() == "fireless"){ 
          
                          str += (*this)(r,c).getMaterial().getColor();
                      }
                      else {
                          int bt = (*this)(r,c).getBurningTime();
                          QColor col (250-20*bt,(80+bt * 160)/(1+bt*bt),0);
                      }
                      label->setStyleSheet(str);
                      layout->addWidget(label, r, c);
                      str="";
          
                      (*this)(r,c).setLabel(label);
          
                  }
              }
              layout->setHorizontalSpacing(0);
              layout->setVerticalSpacing(0);
            
              wid->setLayout(layout);
              wid->show();
          }
          

          I think it originates from here because it does not want to show my start grid here. Thanks in advace!

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

          @Davay said in QGriddlayout works for grid 80*80 but not for 100*100 or more (SIGSEGV error):

          I get a SIGSEGV segmentation fault error in the debugger, it doesn't exactly tell my why.

          I don't see anywhere you have looked at/shown the stack trace for this?

          D 1 Reply Last reply
          0
          • JonBJ JonB

            @Davay said in QGriddlayout works for grid 80*80 but not for 100*100 or more (SIGSEGV error):

            I get a SIGSEGV segmentation fault error in the debugger, it doesn't exactly tell my why.

            I don't see anywhere you have looked at/shown the stack trace for this?

            D Offline
            D Offline
            Davay
            wrote on last edited by
            #11

            @JonB Thank you for your reply, I hope this picture helps but I wasn't really sure what you've asked for (since I'm really unfamiliar with qt (and c++). 69476755-cc96-4a7d-9c9e-d1913c47b835-image.png The first picture is just before I get the Sigsev error and this second one is just after: 7301dcb5-adb9-43b2-a423-731a18eaeb8f-image.png

            JonBJ 1 Reply Last reply
            0
            • D Davay

              @JonB Thank you for your reply, I hope this picture helps but I wasn't really sure what you've asked for (since I'm really unfamiliar with qt (and c++). 69476755-cc96-4a7d-9c9e-d1913c47b835-image.png The first picture is just before I get the Sigsev error and this second one is just after: 7301dcb5-adb9-43b2-a423-731a18eaeb8f-image.png

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

              @Davay
              It probably won't help, but you would need to go back further in the stack trace (bottom window) till you reach somewhere in your own code.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #13

                The debug output looks like you have infinite recursion. With every function call you allocate more stack space. Eventually you will run out of stack space (as it is quite limited compared to the heap) which will in turn result in a segmentation fault.

                Like @JonB already said, you need to provide more of the stack trace until you reach your own code. Click on <More> in the stack trace until you see something familiar. You should also figure out if Qt uses more than 1 Thread. If I am not mistaken GUI stuff runs in Thread #0 and not #1 like you show it. (I might be mistaken about this, though.) Sometimes switching the thread will show your own code in the stack trace.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Davay
                  wrote on last edited by
                  #14

                  @JonB & @SimonSchroeder Thanks a lot for your answers let me start of with the threads, I'll only show those where something new shows up: 06534ce5-7576-49b6-bc54-a62e4c57fa3f-image.png
                  427b1a47-5eb9-490f-90af-354e0ab5bd49-image.png
                  c9170c0b-c429-41c0-9605-9a7e529e4d1a-image.png
                  883871e2-edc3-47aa-87cc-1df9514a894e-image.png
                  2aa92dff-1bc3-46f7-8c26-5c96137a1e0e-image.png

                  92eed9ec-79ae-4fca-bca5-30962454ed84-image.png
                  986ca12d-e65d-456c-bd07-a374c4dc3e56-image.png
                  35300ee1-ae56-42e0-a5e5-d404d368634b-image.png
                  370bffc2-1475-4f04-a3cb-369d9df1632c-image.png
                  Now if I click on more in thread 1 (see the previous reply) it doesn't do anything now if I click on it a couple of times, QT crashes without error or any warning.

                  @SimonSchroeder do you mean with this limited amount of stack space that I can't make more of my clickable labels than lets say than a grid filled with them more than (80 on 80) so about 6400?

                  Pl45m4P 1 Reply Last reply
                  0
                  • D Davay

                    @JonB & @SimonSchroeder Thanks a lot for your answers let me start of with the threads, I'll only show those where something new shows up: 06534ce5-7576-49b6-bc54-a62e4c57fa3f-image.png
                    427b1a47-5eb9-490f-90af-354e0ab5bd49-image.png
                    c9170c0b-c429-41c0-9605-9a7e529e4d1a-image.png
                    883871e2-edc3-47aa-87cc-1df9514a894e-image.png
                    2aa92dff-1bc3-46f7-8c26-5c96137a1e0e-image.png

                    92eed9ec-79ae-4fca-bca5-30962454ed84-image.png
                    986ca12d-e65d-456c-bd07-a374c4dc3e56-image.png
                    35300ee1-ae56-42e0-a5e5-d404d368634b-image.png
                    370bffc2-1475-4f04-a3cb-369d9df1632c-image.png
                    Now if I click on more in thread 1 (see the previous reply) it doesn't do anything now if I click on it a couple of times, QT crashes without error or any warning.

                    @SimonSchroeder do you mean with this limited amount of stack space that I can't make more of my clickable labels than lets say than a grid filled with them more than (80 on 80) so about 6400?

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #15

                    @Davay

                    It probably wont help to solve your problem, but why do you need 10.000 labels or more in a QGridLayout at the same time? Maybe there is a workaround or better/different solution for your use case.
                    -> QGraphicsView+ QGraphicsItems instead of labels in a grid.


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Davay
                      wrote on last edited by
                      #16

                      Well, you are probably right that I don't need them but for a beginner like me it seemed a logical choice to use labels or buttons since those are things I know. I'm trying to make a forest fire simulation and each tile can be made of a different material that can be changed throughout the simulation. Hence they need to be clickable. I would be open to any suggestions on how to do this better of course!

                      JoeCFDJ Pl45m4P 2 Replies Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        Hi,

                        As suggested by @Pl45m4 the Graphics View Framework. You'll be able to build your simulation in an easier way to manage your various tiles on the map.

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

                        1 Reply Last reply
                        1
                        • D Davay

                          Well, you are probably right that I don't need them but for a beginner like me it seemed a logical choice to use labels or buttons since those are things I know. I'm trying to make a forest fire simulation and each tile can be made of a different material that can be changed throughout the simulation. Hence they need to be clickable. I would be open to any suggestions on how to do this better of course!

                          JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on last edited by JoeCFD
                          #18

                          @Davay Is it possible to create a single image for display of your simulation? You can change the colors of its pixels. Your simulation data is generated behind the scene. One tile consists of a matrix of pixels.

                          1 Reply Last reply
                          0
                          • D Davay

                            Well, you are probably right that I don't need them but for a beginner like me it seemed a logical choice to use labels or buttons since those are things I know. I'm trying to make a forest fire simulation and each tile can be made of a different material that can be changed throughout the simulation. Hence they need to be clickable. I would be open to any suggestions on how to do this better of course!

                            Pl45m4P Offline
                            Pl45m4P Offline
                            Pl45m4
                            wrote on last edited by Pl45m4
                            #19

                            @Davay

                            So your "map" looks like raster graphics with a low resolution where each label in some color represents a tile of a different material?
                            Yes, you can do this with the GraphicsView framework.
                            Of course they can be clickable. But there is so much more you can do, when you use the GraphicsView framework (zooming, custom items etc).
                            It probably takes some time to re-design your interface but 6.400 or over 10k labels on a widget is by far not the best solution :)


                            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                            ~E. W. Dijkstra

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              Davay
                              wrote on last edited by
                              #20

                              Thank all of you for your good suggestions, I'll look into them!

                              1 Reply Last reply
                              0
                              • nageshN Offline
                                nageshN Offline
                                nagesh
                                wrote on last edited by
                                #21

                                @Davay one more observations..How many threads do your application has?
                                in stack trace it's shown upto 21.

                                D 1 Reply Last reply
                                0
                                • nageshN nagesh

                                  @Davay one more observations..How many threads do your application has?
                                  in stack trace it's shown upto 21.

                                  D Offline
                                  D Offline
                                  Davay
                                  wrote on last edited by
                                  #22

                                  @nagesh I do not know, I don't tell something about the threads in my application so it happens automatically I think.

                                  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