Results 1 to 4 of 4

Thread: Question about multiples forms.

  1. #1
    Join Date
    Jun 2015
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Question about multiples forms.

    Hello, i have a problem in my application.
    I'm programming an app with several forms; for example:
    i have the class "MainWindow" and "Find_Patient" so i have this files:
    MainWindow.cpp
    MainWindow.h
    MainWindow.ui
    Find_Patient.cpp
    Find_Patient.h
    Find_Patient.ui.

    Suppose that in MainWindow i have a button, and when i click that button, Find_Patient shows up and MainWindow dissapears.
    so this is the code for that:

    Qt Code:
    1. void MainWindow::on_open_find_patient_clicked()
    2. {
    3. Find_Patient *go = new Find_Patient
    4. go->show(); //this is going bring up Find_Patient
    5. this.hide(); //this is going to hide MainWindow
    6. }
    To copy to clipboard, switch view to plain text mode 

    and this is the code for the button on Find_Patient.cpp to back to MainWindow

    Qt Code:
    1. void Find_Patient::on_open_MainWindow_clicked()
    2. {
    3. MainWindow *back = new MainWindow
    4. back->show(); //this is going bring up MainWindow
    5. this.hide(); //this is going to hide Find_Patient
    6. }
    To copy to clipboard, switch view to plain text mode 
    This code is totally functional, but it is not efficient.

    Here's my problem:

    Every time that i will click one of those buttons, the code will create a new object of type MainWindow or Find_Patient.
    Doing this, it will ocupate a peace of memory every time that i click that button, because the previous object is hidden, not destroyed.
    So my question is how i pass through forms?
    This is the right way for doing it? or there is another way?.

    i'm thinking on doing this:
    Qt Code:
    1. MainWindow *back = new MainWindow
    2. back->show(); //this is going bring up MainWindow
    3. this.deleteLater(); //this is going to delete Find_Patient
    To copy to clipboard, switch view to plain text mode 
    but i don't know if this is correct.

    Sorry my bad english, im spanish.

    Thanks!
    Last edited by Bruno1993; 24th June 2015 at 01:33.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about multiples forms.

    1) define a signal in Find_Patient
    2) connect it to the main window's show() slot after creating Find_Patient
    3) emit the signal when you are closing Find_Patient

    You can either make Find_Patient delete itself on close (e.g. setting the WA_DeleteOnClose widget attribute) or keeping the instance around and just showing it again when necessary.

    Cheers,
    _

  3. #3
    Join Date
    Jun 2015
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Question about multiples forms.

    Suppose that i want to keep one instance around and i want to show it or hide it many times... And i want to do that from different clases. Is that possible?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about multiples forms.

    Sure.
    You can either signal the main window that it should show the dialog or make the dialog instance accessible from elsewhere.

    Cheers,
    _

Similar Threads

  1. QNetworkAccessManager and multiples requests
    By hassinoss in forum Qt Programming
    Replies: 7
    Last Post: 26th August 2014, 14:43
  2. More than one forms
    By NewLegend in forum Qt Programming
    Replies: 16
    Last Post: 15th September 2010, 00:32
  3. Multiples QSqlQueryModel and QTableView
    By Netheril in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2010, 18:38
  4. Multiple Forms and vertical layout in forms
    By eva2002 in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2010, 05:05
  5. Layouting "Windows.Forms" like Qt forms
    By Boron in forum Qt Tools
    Replies: 1
    Last Post: 29th April 2008, 22:01

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.