Results 1 to 2 of 2

Thread: realloc() and qRealloc problem

  1. #1
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default realloc() and qRealloc problem

    Hello!

    In the following code

    cell struct declaration:
    Qt Code:
    1. struct cell {
    2. int i, j;
    3. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. cell *Cells= (cell*) malloc (sizeof(cell));
    2. int i, j, k=0;
    3. for (i=0; i<nrow; i++)
    4. for (j=0; j<ncol; j++)
    5. {
    6. k++;
    7. qRealloc(Cells, sizeof(cell) * k);
    8. Cells[k-1].i=i;
    9. Cells[k-1].j=j;
    10. }
    To copy to clipboard, switch view to plain text mode 

    I need to create a dynamic matrix with qRealloc (and I've tried even with realloc() ). if I run this code in VS 6.0 it's ok, but in Qt Creator it raises a segmentation fault error. Moreover if I declare the Cells matrix as a static one (so cell Cells[100]; and comment the realloc) all goes good (of course).

    Is there a known bug on realloc and qRealloc functions in Qt 4? Or I'm trying to do something wrong?

    thanks
    Last edited by harmodrew; 10th August 2010 at 12:27.

  2. #2
    Join Date
    Aug 2010
    Posts
    62
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: realloc() and qRealloc problem

    Solved. I simply had to write:

    Qt Code:
    1. Cells = (cell*) qRealloc(Cells, sizeof(cell) * k);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. realloc
    By mickey in forum General Programming
    Replies: 1
    Last Post: 4th May 2008, 19:59

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.