Results 1 to 7 of 7

Thread: subwindows in application - memory usage

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default subwindows in application - memory usage

    Hello!

    I'm creating simple measurement application which has some windows showing measured data. I'm concern about my device resources. What happening when I'm closing that extra windows? Are they still in memory?

    One of my simple window looks like this (the others are alike):

    Qt Code:
    1. class Pomiary : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Pomiary(QWidget* parent=NULL);
    7.  
    8. private:
    9. void setupUI(); //layout of the window
    10. //some varialbles
    11. };
    To copy to clipboard, switch view to plain text mode 

    That windows have a lot of variables (each one). On my main window I've got QPushButtons that opens that extra windows like this:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. setWindowFlags(Qt::CustomizeWindowHint);
    7.  
    8. OknoPomiary = new Pomiary;
    9.  
    10. QPushButton *button = new QPushButton;
    11. ui->appLayout->addWidget(button,0,0,Qt::AlignHCenter);
    12.  
    13. connect(button,SIGNAL(clicked()),OknoPomiary,SLOT(show()));
    To copy to clipboard, switch view to plain text mode 

    Is it correct way to save my resources? Or maybe application with extra windows should be done in other way? Maybe creating my widow in some kind of extra slot invoked by clicking on button?

    thanks in advance
    best regards
    Tomasz

  2. #2
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: subwindows in application - memory usage

    When you close the window, memory will not be released. But you may use setAttribute(Qt::WA_DeleteOnClose) in your Pomiary constructor to free the memory when you close your window.

  3. The following user says thank you to agathiyaa for this useful post:

    Tomasz (22nd July 2010)

  4. #3
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: subwindows in application - memory usage

    And what if I want to open again that window? Variables will be 'clean'?
    Should I create object of Pomiary class in Main Window constructor, on in the other function invoked by for example button or it doesn't make any difference?

    thanks in advance
    best regards
    Tomasz

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,590
    Thanks
    13
    Thanked 1,586 Times in 1,515 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: subwindows in application - memory usage

    If you delete the object (directly or with Qt::WA_DeleteOnClose) then OknoPomiary becomes invalid and you need to allocate a new instance in order to show it again. The new instance is independent of the old and will have whatever state the constructors give it.

    You currently allocate storage for a Pomiary instance regardless of whether the user has pressed the button to show it (whether this is a big thing is up to you). You could place the logic to allocate and show the window into a slot the push button triggers. The slot could check to see if the window already exists and simply show() it if it does and allocate and show if it does not.

  6. The following user says thank you to ChrisW67 for this useful post:

    Tomasz (23rd July 2010)

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: subwindows in application - memory usage

    It's really funny to see an Aussie use Polish words in English written posts "a Pomiary instance" sounds great
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,590
    Thanks
    13
    Thanked 1,586 Times in 1,515 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: subwindows in application - memory usage

    I aim to please There is an awful lot of language mangling going around in these forums.

  9. #7
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: subwindows in application - memory usage

    Quote Originally Posted by ChrisW67 View Post
    The slot could check to see if the window already exists and simply show() it if it does and allocate and show if it does not.
    So It should be simple if(OknoPomiary) { OknoPomiary->show() } and else create new "a Pomiary instance"? And all in one slot triggered by a button.

    I know Polish names sounds funny, next time I will use English names ;-)

    thanks in advance
    best regards
    Tomasz
    Last edited by Tomasz; 23rd July 2010 at 12:14.

Similar Threads

  1. Bad memory usage on QWebView I think
    By jiturra in forum Qt Programming
    Replies: 15
    Last Post: 21st January 2014, 21:35
  2. Memory usage of simple Qt app
    By DiamonDogX in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2009, 07:53
  3. CPU and Memory Usage
    By philwinder in forum Qt Programming
    Replies: 16
    Last Post: 17th May 2008, 23:25
  4. QString memory usage
    By jogeshwarakundi in forum Newbie
    Replies: 1
    Last Post: 13th December 2007, 07:48
  5. How to determine memory usage?
    By nopalot in forum General Programming
    Replies: 3
    Last Post: 11th February 2007, 20:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.