c++qtsegmentation-faultqt4.8

Segmentation fault when getting QString


Strange problem, already looked into with several colleagues... Using Qt Creator and Qt 4.8.5

Any ideas? Same issue known?

UPDATE

Changed code to this, based on comments, still same issue

    private:
        int id;
        QString name;

    public;
       int getId() { return id; } // OK
       void setId(int setTo) { id = setTo; } 

       QString getName() { return name; } // SIGSEGV
       void setName(QString setTo) { name = setTo; }

Solution

  • thinking further about the way objects are created in memory, I thought that a QString maybe doesn't reserve fixed number of bytes, which could be the cause of this strange behavior and guess what, a dummy change solved my problem...

    This feels like a really "dirty" solution, but at least I can go on with my work ;-) But any idea's on the root cause would really be appreciated! Thanks already for all the valuable comments!!!

    private:
        QString name; // FIRST DEFINE QSTRING
        int id; // THEN DEFINE INT
    
    public;
       int getId() { return id; } // OK
       void setId(int setTo) { id = setTo; } 
    
       QString getName() { return name; } // OK
       void setName(QString setTo) { name = setTo; }