Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: how to launch a wizard from the mainwindow's File Menu

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

    Default Re: how to launch a wizard from the mainwindow's File Menu

    Quote Originally Posted by pkjag View Post
    Not in this context i just vaguely understand it like in assembly i.e a stack overflow.
    Stack overflow has nothing to do with memory leaks.

    What object is causing the leak and in what file should i delete it??
    http://lmgtfy.com?q=memory+leak
    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.


  2. #22
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to launch a wizard from the mainwindow's File Menu

    So i figured that the object causing the memory leak is SkoolCalcWizard wizard but i don't understand why cause i already replaced the pointer notation with the normal object declaration in #3.

    And i do use the object by calling show or return since i have already used both of these functions and they both make my program vanish.

    So i'd like if you could spell it out for me like explicitly.
    Last edited by pkjag; 5th September 2013 at 15:27.

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

    Default Re: how to launch a wizard from the mainwindow's File Menu

    Quote Originally Posted by pkjag View Post
    So i figured that the object causing the memory leak is SkoolCalcWizard wizard but i don't understand why cause i already replaced the pointer notation with the normal object declaration in #3.
    ... which causes your code (the second snippet, the first is fine) to fail because of what was posted in #4, #5 and #11.

    I told you that your code from post #1 was correct apart the compilation errors and the memory leak. Code from #3 (the second snippet) is invalid because of the variable going out of scope.
    Last edited by wysota; 5th September 2013 at 15:59.
    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.


  4. #24
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to launch a wizard from the mainwindow's File Menu

    I think i'm starting to get the hang of this memory leak business. They've defined it as allocating memory and refusing to deallocate it or use it later. If you ask me they should've called it memory block, the name's got more sense. So how should i use the allocated memory to do what i want??

    But i understand you saying i have a variable that's out of scope means that the wizard object is the variable. And being out of scope when the function ends is saying that the function is show() and because it returns immediately after it schedules an event it ends?? that's the tricky part that my mind can't wrap around.

    So what's the difference between code at #1 and the correct code at #3 and which should i use??

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

    Default Re: how to launch a wizard from the mainwindow's File Menu

    Quote Originally Posted by pkjag View Post
    I think i'm starting to get the hang of this memory leak business. They've defined it as allocating memory and refusing to deallocate it or use it later. If you ask me they should've called it memory block, the name's got more sense.
    I don't know who is "they" but this looks like a "memory leak" and not a "memory block" to me:

    Qt Code:
    1. for(int i=0;i<100;++i) new char[1000];
    To copy to clipboard, switch view to plain text mode 

    So how should i use the allocated memory to do what i want??
    I don't have the slightest idea what you mean.

    But i understand you saying i have a variable that's out of scope means that the wizard object is the variable. And being out of scope when the function ends is saying that the function is show() and because it returns immediately after it schedules an event it ends?? that's the tricky part that my mind can't wrap around.
    By the variable going out of scope I mean exactly what is meant in C/C++ when saying about variables going out of scope.

    So what's the difference between code at #1 and the correct code at #3 and which should i use??
    Read my posts again, please. I really don't want to repeat myself again. I'm assuming you have some decent C++ skills so you should be able to handle that yourself. If not, maybe it's time to do some reading on C++. Qt really has nothing to do with this.
    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.


  6. #26
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to launch a wizard from the mainwindow's File Menu

    I do understand C++ but you are being too vague. What variable is out of what function's scope?? since there are two functions there, show() and newFile(). You mentioned i have a memory leak problem but you haven't showed me how i fix that hence my question how i should use the allocated memory thats causing the leak. You previously mentioned sonething along the lines of slots and signals, i've about a months worth experience with Qt and i don't know how to use them in this situation. I don't know why its so difficult for you to help me with this memory leak situation.

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

    Default Re: how to launch a wizard from the mainwindow's File Menu

    Quote Originally Posted by pkjag View Post
    I do understand C++ but you are being too vague. What variable is out of what function's scope??
    If you understood C++ you wouldn't be asking that question.


    Qt Code:
    1. int func() {
    2. A a;
    3. }
    To copy to clipboard, switch view to plain text mode 

    In the code above local variable "a" goes out of scope (its own scope, as in "it dies") when "func" function returns as the stack unwinds destroying all local variables.


    You mentioned i have a memory leak problem but you haven't showed me how i fix
    I did:
    Quote Originally Posted by wysota View Post
    Delete the object causing the leak once you don't need it anymore or use some mechanism (like Qt's parent-child relationship or the signal-slot mechanism together with deleteLater() slot) that will do that for you.
    that hence my question how i should use the allocated memory thats causing the leak.
    Use it any way you want. The point is to seal the leak (aka delete the object) once you are done using it. That's really one of the most basic things in C++ and I'm sure that if you spent at least 10 hours learning that language, you should have been taught (or learnt yourself) to clean up memory once you are finished using it.


    You previously mentioned sonething along the lines of slots and signals, i've about a months worth experience with Qt and i don't know how to use them in this situation. I don't know why its so difficult for you to help me with this memory leak situation.
    You don't need any Qt experience for that. Here is an example:

    Leak:
    Qt Code:
    1. class A {
    2. public:
    3. A() { m_var = 0; }
    4. void func() { m_var = new B; }
    5. private:
    6. B *m_var;
    7. };
    To copy to clipboard, switch view to plain text mode 

    No leak:
    Qt Code:
    1. class A {
    2. public:
    3. A() { m_var = 0; }
    4. ~A() { delete m_var; }
    5. void func() { m_var = new B; }
    6. private:
    7. B *m_var;
    8. };
    To copy to clipboard, switch view to plain text mode 

    Another example:

    Leak:
    Qt Code:
    1. class A {
    2. public:
    3. A() {}
    4. void func() { B *var = new B; var->doSomething(); /* var not needed anymore */ }
    5. };
    To copy to clipboard, switch view to plain text mode 

    No leak:
    Qt Code:
    1. class A {
    2. public:
    3. A() { }
    4. void func() { B var; var.doSomething(); /* var not needed anymore */ }
    5. };
    To copy to clipboard, switch view to plain text mode 

    And another example, this time using Qt's facilities:

    Leak:
    Qt Code:
    1. class A : public QObject {
    2. public:
    3. A(QObject *parent =0) : QObject(parent) { }
    4. void func() { B *var = new B; }
    5. };
    To copy to clipboard, switch view to plain text mode 

    No leak:
    Qt Code:
    1. class A : public QObject {
    2. public:
    3. A(QObject *parent =0) : QObject(parent) { }
    4. void func() { B *var = new B(this); }
    5. };
    To copy to clipboard, switch view to plain text mode 

    And one more:

    Leak:
    Qt Code:
    1. class A {
    2. public:
    3. A() { }
    4. void func() { B *var = new B; }
    5. };
    To copy to clipboard, switch view to plain text mode 

    No leak:
    Qt Code:
    1. class A {
    2. public:
    3. A() { }
    4. void func() { B *var = new B; var->deleteLater(); }
    5. };
    To copy to clipboard, switch view to plain text mode 

    And yet another one:

    Leak:
    Qt Code:
    1. class A : public QObject {
    2. public:
    3. A(QObject *parent =0) : QObject(parent) { }
    4. void func() { B *var = new B; }
    5. };
    To copy to clipboard, switch view to plain text mode 

    No leak:
    Qt Code:
    1. class A : public QObject {
    2. public:
    3. A(QObject *parent =0) : QObject(parent) { }
    4. void func() {
    5. B *var = new B(this);
    6. connect(var, SIGNAL(finishedIamNotUsedAnymore()), var, SLOT(deleteLater()));
    7. }
    8. };
    To copy to clipboard, switch view to plain text mode 

    Let me spell it out again for you: fixing memory leaks means freeing up heap memory before you lose the last handle to that memory (using whatever mechanism you have at hand -- the delete operator, smart pointers or some kind of deferred deletion). This is basic C++ stuff and there are zillons or webpages mentioning "memory leaks" and instructions how to seal them, if in your prior programming education you have not encountered that term.

    Up till now I was assuming you had programming skills, that's why I was telling you "fix the memory leak" and not "please delete the variable you are not using anymore and remember to always free up memory you are not using anymore". Apparently that was my mistake... I guess we have both learned something here.
    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. #28
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: how to launch a wizard from the mainwindow's File Menu

    At last it worked!!!!
    Thanks guys, especially wysota for being patient with me!!!'

Similar Threads

  1. how to add my menu class to my MainWindow?
    By saman_artorious in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2012, 21:27
  2. Replies: 1
    Last Post: 29th September 2011, 11:14
  3. Launch app by opening a file
    By Windsoarer in forum Qt Programming
    Replies: 2
    Last Post: 28th May 2009, 06:22
  4. Replies: 1
    Last Post: 13th May 2009, 03:18
  5. MainWindow Menu bug in Qt 4.2.3?
    By No-Nonsense in forum Qt Programming
    Replies: 4
    Last Post: 11th March 2007, 11:47

Tags for this Thread

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.