Results 1 to 4 of 4

Thread: Open new window when button on main-window is clicked

  1. #1
    Join Date
    Dec 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Open new window when button on main-window is clicked

    Hi
    I am trying to create a Nokia mobile application using Qt. It has two forms/windows (for now) . Window1 is shown below:

    Fig: window1

    When I click on the first button (‘Add’) in window1, I want it to open window2 shown below:

    Fig: window2

    Both were created using Qt Designer in Qt Creator.

    Window1 is the MainWindow template and window2 is of Widget template.

    I also have the following headers and classes. When I run the application, it builds with no errors and I can see the main window but when I click on the add button I don’t see window2.
    CAN ANY ONE HELP ME IDENTIFY WHAT I AM DOING WRONG?


    Fig3: main window header file


    Fig4: main window class file

    I could not attach the window2 header and class file due to the limit on attaching images but the full project can be found here: http://www.nagorik.org/qt/WT.rar

    PLEASE HELP ME GET STARTED WITH THIS PROJECT.
    Thanks in advance for your help.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Open new window when button on main-window is clicked

    For a start, post code in [code] tags, not as images.

    You have an Add push button in the WT Designer UI that you completely ignore: this button does nothing as a result. You then create another push button labelled Add and show it as a top-level window (look carefully when you start the application) and connect it to your slot. When you click the free-standing Add button the second form is shown.

    The second form shows overlaid in a messy fashion on the main form's content because you have given the second form the first form as parent: you probably don't want to do this if the second form is supposed to stand alone.

  3. #3
    Join Date
    Dec 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: Open new window when button on main-window is clicked

    Thanks Chris for your reply.
    I will certainly post code in [CODE] tags next time.

    Regarding providing a parent, how can I prevent memory leaks if I don't provide the first form as a parent.
    Some details on the concept of preventing memory leaks, in the context of multiple forms in Qt, would be very much appreciated.

    Thanks again for your help.

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

    Default Re: Open new window when button on main-window is clicked

    This is just standard C++ memory management. It depends on where and how you use it. For windows that are to be short lived (e.g. modal QDialogs) then you can create them on the stack and they are automatically cleaned up as they go out of scope. If you allocate the memory on the heap with new then you must ensure that delete is called at some point. Usually the destructor of the allocating class is the correct place. Another option is to use one of the "smart" pointers: QScopedPointer or QSharedPointer.

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

    SNK111 (23rd December 2010)

Similar Threads

  1. Replies: 0
    Last Post: 10th September 2010, 13:23
  2. Replies: 2
    Last Post: 4th August 2010, 19:10
  3. Replies: 9
    Last Post: 16th May 2010, 16:21
  4. Replies: 10
    Last Post: 6th July 2008, 09:46
  5. Maximize Window button of Manin Window
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2007, 08:20

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.