Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

2d dynamic memory allocation



  • Hello I am new to Qt C++.
    I am trying to allocate a memory for 2d array like int** array; but its crashing.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    How are you doing the allocation ?
    Did you run your application through the debugger ?



  • do you know that size of the array in advance?
    can you create and access it using subscripts? or what is the reason for creation by pointer...since when talking about arrays the generally accepted access method is by subscript, and only by pointer as a possible optimization later.

    std::string my2dStringArray[20][10];
    20 rows of 10 columns worth of strings now exist.

    or int myInts[] = new int[row*col];
    auto v = myInts[(col * y) + x];


Log in to reply