[Qt-interest] Mixing QT and non QT data structures in c++ causes runtime error

F B fbabetz at yahoo.it
Sat Feb 6 18:00:26 CET 2010


Hi,
I'm doing a little software project and I have to separate the logical part of this program from the graphical interface; I used standard c++ data structures to do the logical part (for example, arrays allocated into the heap, strings, etc.) and obviously, some custom classes that inherit from QWidget or other QT classes for the graphical part.
Every part compiles and works fine but when I add the logical component as data field in the graphical part I obtain a runtime error.

This is a simplified version of my code:

//file.h
GraphicalClass : public QWidget
{
 private:
  Logical_Data_field t; // adding this data field in the structure cause a runtime error
  QT_data_field** gc;
  QGridLayout* l;
 public:
  GraphicalClass(int =20); // constructor
};

//file.cpp
#include"file.h"
GraphicalClass::GraphicalClass(int nc): t(nc), gc(new  QT_data_field*[nc]), l(new QGridLayout())
{
   // (...)
}

The Logical_Data_field is structured in this way:
//file.h
class Logical_Data_field
{
    private:
        const int numberofbox; // number of cell of the array
        cas** c; // array of pointers allocated into the heap
        ind n;
    public:
   // constructor, destructor and other methods
};

The error I obtained is this:
*** glibc detected *** ./GraphicalClass: malloc(): memory corruption: 0x0898d590 ***
followed by a backtrace.


I also tried to initialize the Logical_Data_field in the GraphicalClass with a "new", but the error is still present.
If I put that Data_field inside the code of the constructor of the GraphicalClass the program run but I obtain frequent segmentation fault launching it.

Tell me if you need additional info.
Thank you in advance.

F.



      




More information about the Qt-interest-old mailing list