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. Recurcive repaint problem

Recurcive repaint problem

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 3.3k 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.
  • V Offline
    V Offline
    Vyivrain
    wrote on 24 Jun 2014, 16:43 last edited by
    #1

    Hello, I'm making an app similar to paint, but having a problem with recursive repaint and QVector indexes out of range( I don't know why this is happening ). Here's how my error's look in compiler:
    @ASSERT failure in QVector<T>::operator[]: "index out of range", file ....\5.2.1\mingw48_32\include/QtCore/qvector.h, line 369
    QWidget::repaint: Recursive repaint detected@
    Here're links to my paint.h and paint.cpp files:
    https://github.com/Vyivrain/ProjectFiles/blob/master/mypaint.h
    https://github.com/Vyivrain/ProjectFiles/blob/master/mypaint.cpp
    Thx for answering.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vezprog
      wrote on 24 Jun 2014, 20:18 last edited by
      #2

      Are you using a debugger? Set break points on your paint where you access the vector elements. Check your variable window and look at the size, you are exceeding the size of the multi dimensional array somewhere in your code.

      Also, you have no bound checks on your vector in your repaint which from what I can see will most likely occur before your mouse press event...therefore, your inner vector in your multi dimensional array will be empty and you will 'exceed the bounds of the array'.

      include <QDebug> at the top of your .cpp file, and before you access your vector in the paint method, print a statement to the log window:

      @
      qDebug() << geo.size();
      @

      Then start working backwards to figure out where the issue is coming from.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vyivrain
        wrote on 24 Jun 2014, 20:38 last edited by
        #3

        If it was so obvious, I wouldn't post this question.Just to correct this question, my error comes, when I click on any button. If you can see the code, there're no ways to compute geom.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on 24 Jun 2014, 20:50 last edited by
          #4

          Please describe a bit mor,when this occures.
          At startup? After doing what?

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vyivrain
            wrote on 24 Jun 2014, 20:58 last edited by
            #5

            The app starts nicely, but when I try to press any button this stuff happens. If you want the app is on github you can download hole project there. I think the hole problem is mouseEvent and paintEvent, because f.e. rectButtonClicked, ellButtonClicked, lineButtonClicked is only assure, that only one button is active( checked ) at a time. And another methods are just for initialization.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on 24 Jun 2014, 21:01 last edited by
              #6

              Hi,

              I just started the programin the debugger.
              what fails is:

              @
              void MyPaint::paintEvent(QPaintEvent *pe)
              {
              QPainter painter( this );
              if( lineButClicked )
              {
              painter.drawLine( geom[index][0], geom[index][1] ); //<-- here
              index++;
              pointsNum = 0;
              }
              @

              geom has size 1, geom[0] has size 0, but you access elements of it.

              you activate the sections inpaint with clicking the button. But the geom vector does contain an empty vector.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vyivrain
                wrote on 24 Jun 2014, 21:03 last edited by
                #7

                Okay, I just don't understand why it repaints , when I press the button.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on 24 Jun 2014, 21:07 last edited by
                  #8

                  But your code hasmor problems.
                  You are painting on the dialog, not on the view for example.

                  @
                  void MyPaint::paintEvent(QPaintEvent *pe)
                  {
                  QPainter painter( this );
                  painter.setPen(Qt::red);
                  if( lineButClicked )
                  {
                  if(geom[index].size() >= 2)
                  {
                  painter.drawLine( geom[index][0], geom[index][1] );
                  index++;
                  pointsNum = 0;
                  }
                  }
                  else if( ellButClicked )
                  {
                  if(geom[index].size() >= 2)
                  {
                  painter.drawRect( QRect( geom[index][0], geom[index][1] ) );
                  index++;
                  pointsNum = 0;
                  }
                  }
                  else if ( rectButClicked )
                  {
                  if(geom[index].size() >= 2)
                  {
                  painter.drawEllipse( QRect( geom[index][0], geom[index][1] ) );
                  index++;
                  pointsNum = 0;
                  }
                  }
                  }

                  @

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on 24 Jun 2014, 21:09 last edited by
                    #9

                    [quote author="Vyivrain" date="1403643808"]Okay, I just don't understand why it repaints , when I press the button.[/quote]

                    it may repaint whenever it wants. Maybe due to the cursor change.

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      Vyivrain
                      wrote on 24 Jun 2014, 21:13 last edited by
                      #10

                      Yeah, I know, but I can't paint on the dialog, because I have a condition in mouseEvent. But the main thing is repaint. How ca I deal with it, so it will repaint only, when mouseEvent occurs and there I'll use update to launch paintEvent. And because I didn't know that repaint calls whenever it wants , it became obvious error, my bad =(.

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        Vyivrain
                        wrote on 24 Jun 2014, 21:39 last edited by
                        #11

                        Okay, did that with another if statement. But , I can paint on the just if I do QPainter( view ) correct? Nevermind, did that too.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          giesbert
                          wrote on 26 Jun 2014, 16:16 last edited by
                          #12

                          You have to overwrite the paint event of the widget, where you want to paint in.
                          You subclassed the dialog, hence you draw in the dialog.

                          @
                          void MyPaint::paintEvent(QPaintEvent *pe)
                          @

                          MyPaint is the dialog...

                          [quote author="Vyivrain" date="1403644402"]Yeah, I know, but I can't paint on the dialog, because I have a condition in mouseEvent. But the main thing is repaint. How ca I deal with it, so it will repaint only, when mouseEvent occurs and there I'll use update to launch paintEvent. And because I didn't know that repaint calls whenever it wants , it became obvious error, my bad =(.[/quote]

                          Repaints can also occure, if yomeone puts a window in front of yours and away again, there are many reasons.

                          Nokia Certified Qt Specialist.
                          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                          1 Reply Last reply
                          0

                          10/12

                          24 Jun 2014, 21:13

                          • Login

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