Results 1 to 4 of 4

Thread: Project not showing/crashing when adding a simple line of code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2021
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Project not showing/crashing when adding a simple line of code

    I ran my code in VSC and after some seconds it return the bad_alloc error, which means it was indeed an absurd amount of objects. Each entry of my matrix is an object I called "Cell" and my goal was for each cell to have 8 other cells as neighbours. Since NCOL is 40, I thought I would have 40*8 obejcts in the neighbours lists. Seeing your explanation, I realize I had the math all wrong and although I don't think it is as bad as you mentioned, it is still an exponential amount of objects which is not good.

    Anyways, I followed your suggestion of making a list of pairs and the app is now running fine, so thank you

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,327
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Project not showing/crashing when adding a simple line of code

    Since NCOL is 40, I thought I would have 40*8 objects
    Actually 40 * 40 * 8 if your math had been correct. But I am not sure if I can calculate the true number.

    So let's see:

    For the first row:

    mat[0][0] contains 8 copies of mat, none of which have copies of mat.
    mat[0][1] contains 8 more copies, one of which (mat[0][0]) also has 8 copies
    mat[0][2] - mat[0][38] also each contain 8 copies, one of which (mat[0][n-1]) has 8 more
    mat[0][39] has 8 copies plus 16 more (mat[0][0] and mat[0][38]) (I think your grid wraps)

    For the second row:

    mat[1][0] has 8 copies, plus mat[0][0] and mat[0][1] for 16 more. But mat[0][1] also has mat[0][0] for 8 more.
    mat[1][2] has 8, plus mat[0][0], mat[0][1] and mat[0][2] for 24 more. The last two have [0][n-1] for another 16
    same for 3 - 38.
    mat[1][39] has 8 plus 24 plus 16 plus the 32 from mat[1][0] because of wrapping

    and it just gets worse. By the time you get to [39][39] the total is somewhere near a gazillion. :-)

    Glad the simpler solution worked for you.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. [UWP, Qt 5.10] App crashing everytime before showing drop down menu
    By BryanTriana in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 19th March 2018, 13:20
  2. Replies: 2
    Last Post: 11th July 2013, 17:48
  3. QTableWidget showing white line
    By deepal_de in forum Qt Programming
    Replies: 6
    Last Post: 25th May 2011, 09:06
  4. program crashing randomly code -1073741819
    By feraudyh in forum General Programming
    Replies: 6
    Last Post: 21st September 2010, 17:07
  5. Qt is crashing when showing this tooltip. Why?
    By kalos80 in forum Qt Programming
    Replies: 16
    Last Post: 27th July 2010, 10:05

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.