Results 1 to 19 of 19

Thread: How to show a QDialog ( Designed ) ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show a QDialog ( Designed ) ?

    I cannot understand what should i change on what_ever_dialog_class_with_ui ? look what i have done..

    Qt Code:
    1. #include "example.h"
    2. #include "ui_example.h"
    3. #include "hi.h" //include the header file
    4.  
    5. example::example(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::example)
    8.  
    9. {
    10. ui->setupUi(this);
    11. QDialog *gamatos = new QDialog(this);
    12. connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked())); //connect... the signal with slot ...
    13. }
    14.  
    15. example::~example()
    16. {
    17. delete ui;
    18. }
    19.  
    20. void example::on_pushButton_clicked()
    21.  
    22. {
    23. //use the other class to instantiate the QDialog or the QDialog derived class (with or without ui)
    24. hi.h *gamatos = new QDialog(this); //you need to pass 'this' as parent so that you don't get a memory leak
    25. gamatos->show(); //you show the dialog
    26. }
    27.  
    28. void example::changeEvent(QEvent *e)
    29. {
    30. QMainWindow::changeEvent(e);
    31. switch (e->type()) {
    32. case QEvent::LanguageChange:
    33. ui->retranslateUi(this);
    34. break;
    35. default:
    36. break;
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 

  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: How to show a QDialog ( Designed ) ?

    Qt Code:
    1. #include "example.h"
    2. #include "ui_example.h"
    3. #include "hi.h" //include the header file
    4.  
    5. example::example(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::example)
    8. {
    9. ui->setupUi(this);
    10.  
    11. // note that the declaration of pointer can be done only once
    12.  
    13. connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked())); //connect... the signal with slot ...
    14.  
    15. }
    16.  
    17. example::~example()
    18. {
    19. delete ui;
    20. }
    21.  
    22. void example::on_pushButton_clicked()
    23. {
    24. //use the other class to instantiate the QDialog or the QDialog derived class (with or without ui)
    25.  
    26. hi *gamatos = new hi(this); //this is valid if the class name is "hi"... replace that with your class name //you need to pass 'this' as parent so that you don't get a memory leak
    27.  
    28. gamatos->show(); //you show the dialog
    29. }
    30.  
    31. void example::changeEvent(QEvent *e)
    32. {
    33. QMainWindow::changeEvent(e);
    34. switch (e->type()) {
    35. case QEvent::LanguageChange:
    36. ui->retranslateUi(this);
    37. break;
    38. default:
    39. break;
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 

    NOTE: the code changed a bit... i corrected in the previous post, but you already copied... you can't declare the pointer twice (you don't declare it in the constructor, only in the slot)

  3. #3
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show a QDialog ( Designed ) ?

    Ok i founded it.. .But know two Qdialogs are been shown :P

    Qt Code:
    1. #include "example.h"
    2. #include "ui_example.h"
    3. #include "hi.h" //include the header file
    4.  
    5. example::example(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::example)
    8.  
    9. {
    10. ui->setupUi(this);
    11. connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked())); //connect... the signal with slot ...
    12. }
    13.  
    14. example::~example()
    15. {
    16. delete ui;
    17. }
    18.  
    19. void example::on_pushButton_clicked()
    20.  
    21. {
    22. //use the other class to instantiate the QDialog or the QDialog derived class (with or without ui)
    23. hi *gamatos = new hi(this); //you need to pass 'this' as parent so that you don't get a memory leak
    24. gamatos->show(); //you show the dialog
    25. }
    26.  
    27. void example::changeEvent(QEvent *e)
    28. {
    29. QMainWindow::changeEvent(e);
    30. switch (e->type()) {
    31. case QEvent::LanguageChange:
    32. ui->retranslateUi(this);
    33. break;
    34. default:
    35. break;
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: How to show a QDialog ( Designed ) ?

    See the constructor... and the edits of my previous posts... you initialize the second dialog twice (create two dialogs... with two pointers that have the same name...)

  5. #5
    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: How to show a QDialog ( Designed ) ?

    Or, maybe the name of the slot match the autoconnect rules (i gave you a link in a previous post)

    You can rename the slot: something like
    Qt Code:
    1. void example::openDialog() //and connect with this slot name
    2. {
    3. //use the other class to instantiate the QDialog or the QDialog derived class (with or without ui)
    4. hi *gamatos = new hi(this); //you need to pass 'this' as parent so that you don't get a memory leak
    5. gamatos->show(); //you show the dialog
    6. }
    To copy to clipboard, switch view to plain text mode 

    Or don't connect manually and let autoconnect do the connection
    Last edited by Zlatomir; 17th August 2010 at 19:59. Reason: i forgot to rename the slot

  6. #6
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show a QDialog ( Designed ) ?

    Ok it works... Many thanks.. I need it..

Similar Threads

  1. Replies: 7
    Last Post: 25th July 2016, 14:42
  2. How to show a QDialog ( Designed ) ?
    By Bong.Da.City in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2010, 16:54
  3. use QDialog to show file name
    By damonlin in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2008, 13:52
  4. can't show my QDialog
    By sincnarf in forum Qt Programming
    Replies: 3
    Last Post: 22nd October 2007, 09:33
  5. QDialog: show() and exec() together in constructor?
    By Teuniz in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2007, 11:43

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
  •  
Qt is a trademark of The Qt Company.