Results 1 to 10 of 10

Thread: Error after putting in QGraphicView Codes

  1. #1
    Join Date
    May 2013
    Posts
    47
    Qt products
    Qt5
    Platforms
    Windows

    Default Error after putting in QGraphicView Codes

    Qt Code:
    1. terminate called after throwing an instance of 'std::bad_alloc'
    2. what(): std::bad_alloc
    3. terminate called recursively
    4. terminate called recursively
    5. terminate called recursively
    6. terminate called recursively
    7. terminate called recursively
    8. terminate called recursively
    9. terminate called recursively
    10. terminate called recursively
    11. terminate called recursively
    12. terminate called recursively
    13. terminate called recursively
    14. terminate called recursively
    15. terminate called recursively
    16. terminate called recursively
    17. terminate called recursively
    18. terminate called recursively
    19. terminate called recursively
    20. terminate called recursively
    21. terminate called recursively
    22. terminate called recursively
    23. terminate called recursively
    24. terminate called recursively
    25. terminate called recursively
    26. terminate called recursively
    27. D:\project1\Qt\build-QtCreatorMP-Desktop-Debug\debug\QtCreatorMP exited with code 3
    To copy to clipboard, switch view to plain text mode 


    I am getting this errors after putting QGraphicsView code into it

    h file
    Qt Code:
    1. private:
    2. QGraphicsRectItem*rectangle;
    To copy to clipboard, switch view to plain text mode 
    cpp file
    Qt Code:
    1. scene=new QGraphicsScene(this);
    2. ui->graphicsView->setScene(scene);
    3. QBrush yelloBrush(Qt::yellow);
    4. QBrush magentaBrush(Qt::magenta);
    5. QBrush greenBrush(Qt::green);
    6.  
    7. QPen Linepen(Qt::black);
    8. Linepen.setWidth(2);
    9.  
    10.  
    11.  
    12.  
    13. //BASAL
    14. rectangle=scene->addRect(50,220,100,-50,Linepen,magentaBrush);//LAST 1st HOUR BAR CHART
    15. rectangle=scene->addRect(200,220,100,-50,Linepen,magentaBrush);//LAST 2nd HOUR BAR CHART
    16. rectangle=scene->addRect(350,220,100,-50,Linepen,magentaBrush);//LAST 3th HOUR BAR CHART
    17. rectangle=scene->addRect(500,220,100,-50,Linepen,magentaBrush);//LAST 4TH HOUR BAR CHART
    18. rectangle=scene->addRect(650,220,100,-50,Linepen,magentaBrush);//LAST 5th HOUR BAR CHART
    19. //BASAL
    20.  
    21. //PATIENT
    22. //TO ADD ON TOP OF THE GRAPH ,BREAL Y +Y OF BASAL
    23. rectangle=scene->addRect(50,220-50,100,-50,Linepen,yelloBrush);//LAST 1st HOUR BAR CHART
    24. rectangle=scene->addRect(200,220-50,100,-50,Linepen,yelloBrush);//LAST 2nd HOUR BAR CHART
    25. rectangle=scene->addRect(350,220-50,100,-50,Linepen,yelloBrush);//LAST 3th HOUR BAR CHART
    26. rectangle=scene->addRect(500,220-50,100,-50,Linepen,yelloBrush);//LAST 4TH HOUR BAR CHART
    27. rectangle=scene->addRect(650,220-50,100,-50,Linepen,yelloBrush);//LAST 5th HOUR BAR CHART
    28. //PATIENT
    29.  
    30. //CLINICIAN
    31. //TO ADD ON TOP OF THE GRAPH ,BREAL Y +Y OF BASAL AND CLINICIAN
    32. rectangle=scene->addRect(50,220-50-50,100,-50,Linepen,greenBrush);//LAST 1st HOUR BAR CHART
    33. rectangle=scene->addRect(200,220-50-50,100,-50,Linepen,greenBrush);//LAST 2nd HOUR BAR CHART
    34. rectangle=scene->addRect(350,220-50-50,100,-50,Linepen,greenBrush);//LAST 3th HOUR BAR CHART
    35. rectangle=scene->addRect(500,220-50-50,100,-50,Linepen,greenBrush);//LAST 4TH HOUR BAR CHART
    36. rectangle=scene->addRect(650,220-50-50,100,-50,Linepen,greenBrush);//LAST 5th HOUR BAR CHART
    37. //CLINICIAN
    38. line=scene->addLine(0,220,790,220,Linepen);//x axis
    39. line=scene->addLine(790,220,780,215,Linepen);//> for x axis
    40. line=scene->addLine(790,220,780,225,Linepen);//> for x axis
    41.  
    42. line=scene->addLine( 20,0,20,240,Linepen);//y axis
    43. line=scene->addLine(20,0,15,10,Linepen);//> for y axis
    44. line=scene->addLine(20,0,25,10,Linepen);//> for y axis
    45.  
    46.  
    47. line=scene->addLine( 15,215,25,215,Linepen);//y Coordinate (1)
    48. line=scene->addLine( 15,210,25,210,Linepen);//y Coordinate (2
    49. line=scene->addLine( 15,205,25,205,Linepen);//y Coordinate (3)
    50. line=scene->addLine( 15,200,25,200,Linepen);//y Coordinate (4)
    51. line=scene->addLine( 15,195,25,195,Linepen);//y Coordinate (5)
    52. line=scene->addLine( 15,190,25,190,Linepen);//y Coordinate (6)
    53. line=scene->addLine( 15,185,25,185,Linepen);//y Coordinate (7)
    54. line=scene->addLine( 15,180,25,180,Linepen);//y Coordinate (8)
    55. line=scene->addLine( 15,175,25,175,Linepen);//y Coordinate (9)
    56.  
    57. line=scene->addLine( 10,170,30,170,Linepen);//y Coordinate (10)
    58. line=scene->addLine( 15,165,25,165,Linepen);//y Coordinate (11)
    59. line=scene->addLine( 15,160,25,160,Linepen);//y Coordinate (12
    60. line=scene->addLine( 15,155,25,155,Linepen);//y Coordinate (13)
    61. line=scene->addLine( 15,150,25,150,Linepen);//y Coordinate (14)
    62. line=scene->addLine( 15,145,25,145,Linepen);//y Coordinate (15)
    63. line=scene->addLine( 15,140,25,140,Linepen);//y Coordinate (16)
    64. line=scene->addLine( 15,135,25,135,Linepen);//y Coordinate (17)
    65. line=scene->addLine( 15,130,25,130,Linepen);//y Coordinate (18)
    66. line=scene->addLine( 15,125,25,125,Linepen);//y Coordinate (19)
    67.  
    68. line=scene->addLine( 10,120,30,120,Linepen);//y Coordinate (20)
    69. line=scene->addLine( 15,115,25,115,Linepen);//y Coordinate (21)
    70. line=scene->addLine( 15,110,25,110,Linepen);//y Coordinate (22)
    71. line=scene->addLine( 15,105,25,105,Linepen);//y Coordinate (23)
    72. line=scene->addLine( 15,100,25,100,Linepen);//y Coordinate (24)
    73. line=scene->addLine( 15,95,25,95,Linepen); //y Coordinate (25)
    74. line=scene->addLine( 15,90,25,90,Linepen); //y Coordinate (26)
    75. line=scene->addLine( 15,85,25,85,Linepen); //y Coordinate (27)
    76. line=scene->addLine( 15,80,25,80,Linepen); //y Coordinate (28)
    77. line=scene->addLine( 15,75,25,75,Linepen); //y Coordinate (29)
    78. line=scene->addLine( 10,70,30,70,Linepen); //y Coordinate (30)
    79.  
    80. line=scene->addLine( 15,65,25,65,Linepen); //y Coordinate (31)
    81. line=scene->addLine( 15,60,25,60,Linepen); //y Coordinate (32)
    82. line=scene->addLine( 15,55,25,55,Linepen); //y Coordinate (33)
    83. line=scene->addLine( 15,50,25,50,Linepen); //y Coordinate (34)
    84. line=scene->addLine( 15,45,25,45,Linepen); //y Coordinate (35)
    85. line=scene->addLine( 15,40,25,40,Linepen); //y Coordinate (36)
    86. line=scene->addLine( 15,35,25,35,Linepen); //y Coordinate (37)
    87. line=scene->addLine( 15,30,25,30,Linepen); //y Coordinate (38)
    88. line=scene->addLine( 15,25,25,25,Linepen); //y Coordinate (39)
    89. line=scene->addLine( 10,20,30,20,Linepen); //y Coordinate (40)
    90.  
    91.  
    92. yText0=scene->addText("0");
    93. yText0->setPos(7,215);
    To copy to clipboard, switch view to plain text mode 

    I Put the above cpp codes inside a timer(1000) which runs every sec . I am doing this as in the future i am going to change the height to a variable which will get data from a database and set the height of it . That why i use the timer so it can keep updating . Anyway to solve this ?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Error after putting in QGraphicView Codes

    Your program is exhausting your system's memory. Start with the observation that you are creating a whole graphics scene repeatedly and this is not being cleaned up.

  3. #3
    Join Date
    May 2013
    Posts
    47
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Error after putting in QGraphicView Codes

    I see so what should i do ? Does the problem lies with the QGraphicView ?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Error after putting in QGraphicView Codes

    No, the problem is not in Qt. Fix your code. We cannot see that, you can.

  5. #5
    Join Date
    May 2013
    Posts
    47
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Error after putting in QGraphicView Codes

    I check the processes my program took up 1.6++ gb mem . I check my codes. I implemented the graphic view in a timer. guess that causes it to keep running and adding to the memory . Is there a way to like reset the graphic view and call it back again ?


    Added after 6 minutes:


    infusion.cppinfusion.h


    The above are my codes, feel free to take a look .
    Last edited by 020394; 5th September 2013 at 04:50.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Error after putting in QGraphicView Codes

    Your program is creating a new scene graph every millisecond (or thereabouts) as a result of the timer expiring. You never delete the old one... you exhaust system memory rather quickly.

    The other timer (the one that actually updates a clock display) is probably pegging your CPU at about 100% busy-polling when that is entirely unnecessary.
    Last edited by ChrisW67; 5th September 2013 at 05:05.

  7. #7
    Join Date
    May 2013
    Posts
    47
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Error after putting in QGraphicView Codes

    I see , I tried using a 1sec timer , The memory is increasing slower than before . It is ok to put the QGraphic codes in a timer right ? Is it ok to keep creating a new scene graph using a timer ? How to delete the old one ?

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Error after putting in QGraphicView Codes

    Is it ok to keep creating a new scene graph using a timer ?
    Technically fine. Probably not sane though. Ask yourself, "Why am I creating a whole new graphical display every second?" Typical usage would be to construct the scene once and manipulate it as time goes by.
    How to delete the old one ?
    The C++ delete operator or scene->deleteLater(). Fix the busy polling if you want deleteLater() to function well.

  9. #9
    Join Date
    May 2013
    Posts
    47
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Error after putting in QGraphicView Codes

    I see . i was thinking of that too , but i tried to put it out of the timer but the graph would not update efficiently , need to switch to another tab and back in order to see the change . For the deleteLater(), should i put it in another timer to delete the scene every 2-5 sec ?


    Added after 1 46 minutes:


    Ok i tried to solve it , not sure whether it is the right way . I added a scene->update() inside the same timer and create the new scene graph outside the timer .
    Last edited by 020394; 6th September 2013 at 04:01.

  10. #10
    Join Date
    May 2013
    Posts
    47
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Error after putting in QGraphicView Codes

    The C++ delete operator or scene->deleteLater(). Fix the busy polling if you want deleteLater() to function well.
    I tried using deletelater() but it seems there is a problem , the program seems to stop working . You said about Busy polling , how to do that? I tried to use destroyed() on my scene/ui->graphicview but it seems that it does not work as the memory of the process is still running .


    Added after 1 15 minutes:


    Besides using the deletelater(), I seem to find another method not sure whether I did it correctly . I used scene->clear() and put it in the timer . then later sceneupdate() after that to update the ones i need to show .
    Last edited by 020394; 6th September 2013 at 09:23.

Similar Threads

  1. QGraphicView Optimizing cpu
    By fkili in forum Newbie
    Replies: 4
    Last Post: 27th September 2012, 14:02
  2. How to use QGraphicView?
    By karthic in forum Newbie
    Replies: 12
    Last Post: 27th April 2012, 08:06
  3. Replies: 2
    Last Post: 22nd April 2011, 00:39
  4. Error codes in QtXml
    By suneel1310 in forum Qt Programming
    Replies: 0
    Last Post: 7th September 2010, 08:39
  5. my QGraphicView problem
    By irmakci in forum Qt Programming
    Replies: 3
    Last Post: 19th July 2008, 18:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.