Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Destructor array of object
Forum Updated to NodeBB v4.3 + New Features

Destructor array of object

Scheduled Pinned Locked Moved C++ Gurus
24 Posts 5 Posters 15.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stukdev
    wrote on last edited by
    #21

    If i run valgrind its say so that i've memory lost in
    @
    test = new Test();
    @

    So is correct use delete on descrutor? But i don't understand why my app crash for corrupted double-linked.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #22

      The code looks ok. I don't know what's going wrong here. Can you provide a complete test case?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stukdev
        wrote on last edited by
        #23

        After hours i found the problem. The problem is a desctructor of QString. I have one class that load some string from a file and store it in a vector (now i can use a QList but this is old code). This vector is used by some class and is copy. In this old project there aren't delete and the program have much memory leak. The code is this:

        @//Class that load string

        class Loader
        {
        public:
        Loader();
        ~Loader();
        QString* getList();
        private:
        QString str[500];
        };

        Loader::Loader()
        {
        for(quint16 a=0;a<500;a++)
        str[a] = "a"; //This is example fill str with 'a'
        }

        //This is another class that have loader class and call descructor
        class Test : public QDialog, private Ui::Dprodotti {
        Q_OBJECT
        public:
        Test(QWidget *parent = 0);
        ~Test();

        private:
        Loader *loader;
        QString myStr[500];

        private slots:
        void on_pushButton_clicked();
        };

        Test::Test(QWidget *parent) : QDialog(parent)
        {
        setupUi(this);

        loader = new Loader();
        memcpy(myStr,product->getList(),sizeof(myStr));
        
        setAttribute(Qt::WA_DeleteOnClose);
        

        }

        Test::~Test()
        {
        delete loader;
        }

        void Test::on_pushButton_clicked()
        {
        close();
        }@

        There something wrong in that QString vector but i don't understand what...

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #24

          Use [[Doc:QStringList]] and get rid of memcopy and all the dangerous pointer stuff. It's not necessary here.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved