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

Thiago Macieira thiago at kde.org
Sat Feb 6 18:31:06 CET 2010


Em Sábado 6. Fevereiro 2010, às 18.00.26, F B escreveu:
> 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.

We need the code that allocates and destroys the GraphicalClass.

Preferably, make it a small, self-contained example showing the issue at hand. 
While creating this example, you may even find your issue yourself.

(Please limit to 200 lines)
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100206/729e9daa/attachment.bin 


More information about the Qt-interest-old mailing list