Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt 4.8.7 memory artefacts

Qt 4.8.7 memory artefacts

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 448 Views
  • 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.
  • P Offline
    P Offline
    Paulll
    wrote on last edited by
    #1

    I need to use Qt 4.8.7 for Embedded Linux to create a very simple project for testing.
    Project includes 2 forms - Dialog (consists of QTextEdit and button. Button clears
    QTextEdit and QClipboard) and MainWindow (consists of button that exec Dialog).

    I edit text, copy part of it. Then clear editor and clipboard. I can't paste text after that,
    but I dump memory using gcore and see text that I copied (several copies in html form).
    What are these objects left in memory? Are these temporary objects or memory leaks?
    Or I use something incorrectly.

    My code:
    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
        class MainWindow;
    }
    
    class Dialog;
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    public:
        MainWindow(QWidget * parent = 0);
        virtual ~MainWindow();
    
    public slots:
        void slotOpenEditor();
        void slotDeleteEditor();
    
    private:
        Ui::MainWindow * ui;
        Dialog * dlg;
    };
    
    #endif // MAINWINDOW_H
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "widget.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent),
          ui( new Ui::MainWindow ),
          dlg( 0 )
    {
        ui->setupUi(this);
        connect(ui->openEditor, SIGNAL(clicked()), this, SLOT(slotOpenEditor()));
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    
        delete dlg;
        dlg = 0;
    }
    
    void MainWindow::slotOpenEditor()
    {
        dlg = new Dialog();
        connect(dlg, SIGNAL(finished(int)), this, SLOT(slotDeleteEditor()));
        dlg->exec();
    }
    
    void MainWindow::slotDeleteEditor()
    {
        disconnect(dlg, SIGNAL(finished(int)), this, SLOT(slotDeleteEditor()));
        delete dlg;
        dlg = 0;
    }
    

    widget.h

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QDialog>
    
    namespace Ui {
        class Dialog;
    }
    
    class Dialog : public QDialog
    {
        Q_OBJECT
    public:
        Dialog(QWidget * parent = 0);
        virtual ~Dialog();
    public slots:
        void slotCleanClipboard();
    private:
        Ui::Dialog * ui;
    };
    
    #endif // WIDGET_H
    

    widget.cpp

    #include "widget.h"
    #include "ui_Dialog.h"
    
    #include <QDebug>
    #include <QClipboard>
    #include <QObject>
    
    Dialog::Dialog(QWidget *parent)
        : QDialog(parent),
          ui( new Ui::Dialog )
    {
        ui->setupUi(this);
        connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(slotCleanClipboard()));
        connect(ui->clearButton, SIGNAL(clicked()), ui->textEdit, SLOT(clear()));
    }
    
    void Dialog::slotCleanClipboard()
    {
        QApplication::clipboard()->clear();
    }
    
    Dialog::~Dialog()
    {
        delete ui;
    }
    
    

    main.cpp

    #include <QtGui>
    
    #include "mainwindow.h"
    
    int main(int argc, char** argv)
    {
        QApplication app(argc, argv);
        MainWindow mainWindow;
    
        mainWindow.show();
    
        return app.exec();
    }
    

    Thanks for answers.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      AFAIK, unless you specifically clean a memory region before releasing it, it will contain the "old data" until it gets overwritten.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3

      • Login

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