Results 1 to 3 of 3

Thread: my window disappears quickly

  1. #1
    Join Date
    May 2010
    Posts
    20
    Thanks
    7
    Qt products
    Qt4

    Unhappy my window disappears quickly

    Hi everyone..

    I have problem in my project..
    look at this first:
    in dialog3.cpp
    Qt Code:
    1. void Dialog3::openD4()
    2. {
    3. drawGraph g;
    4. g.show();
    5. }
    To copy to clipboard, switch view to plain text mode 

    I have drawGraph.h , drawGraph.cpp ,and drawGraph.ui files
    ( I draw circles and add bottons inside it)
    I call them window by define object and call show functon to display it after dialog3..

    but it disappears quickly
    so, I cann't see it!

    when I call it in main.cpp,it doesn't disappear!!

    anyone have idea about that?
    Last edited by Abeer; 30th May 2010 at 01:14.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: my window disappears quickly

    That happens because you allocate memory (for your g) on that function stack.

    You should allocate memory on the heap, so the object remains after the function terminates, like this:
    Qt Code:
    1. drawGraph *g = new drawGraph; //create a pointer and allocate with new
    2. g->show(); // use -> to access members
    To copy to clipboard, switch view to plain text mode 

    And make sure that your g pointer gets a parent, or else you should call delete g; in the class destructor (so that you wont get a memory leak)

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

    zoz (30th May 2010)

  4. #3
    Join Date
    May 2010
    Posts
    20
    Thanks
    7
    Qt products
    Qt4

    Default Re: my window disappears quickly

    Quote Originally Posted by Zlatomir View Post
    That happens because you allocate memory (for your g) on that function stack.

    You should allocate memory on the heap, so the object remains after the function terminates, like this:
    Qt Code:
    1. drawGraph *g = new drawGraph; //create a pointer and allocate with new
    2. g->show(); // use -> to access members
    To copy to clipboard, switch view to plain text mode 

    And make sure that your g pointer gets a parent, or else you should call delete g; in the class destructor (so that you wont get a memory leak)
    Thanks a lot
    Thanks a lot Zlatomir

    I see my window now clearly

    I am grateful to you for helping..
    thanks again..

    \

Similar Threads

  1. Focus in QDockWidget disappears
    By Debilski in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2011, 13:40
  2. QGraphicsView scroll bars disappears
    By jano_alex_es in forum Qt Programming
    Replies: 4
    Last Post: 25th November 2009, 15:17
  3. QTableView, QSqlTableModel - data disappears
    By msh in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2008, 12:50
  4. Character from argument disappears
    By Pepe in forum Qt Programming
    Replies: 13
    Last Post: 20th June 2007, 00:48
  5. Displaying Text Quickly
    By taylor34 in forum Qt Programming
    Replies: 6
    Last Post: 2nd March 2006, 15:09

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.