Results 1 to 3 of 3

Thread: New Dialog Problem

  1. #1
    Join Date
    Jul 2018
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default New Dialog Problem

    Why is this happening?
    Adsız.png

    //mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include<QtCore>
    4. #include<QtGui>
    5. #include<QMessageBox>
    6. #include"secondwindow.h"
    7.  
    8. MainWindow::MainWindow(QWidget *parent) :
    9. QMainWindow(parent),
    10. ui(new Ui::MainWindow)
    11. {
    12. ui->setupUi(this);
    13. }
    14.  
    15. MainWindow::~MainWindow()
    16. {
    17. delete ui;
    18. }
    19.  
    20. void MainWindow::on_pushButton_clicked()
    21. {
    22. QMessageBox::information (this, "Title", "kaydedildi");
    23. }
    24.  
    25. [B]void MainWindow::on_pushButton_3_clicked() //When i clicked this button the problem occurs
    26. {
    27. msecond = new Secondwindow(this);
    28. msecond->show();
    29. }[/B]
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2018
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: New Dialog Problem

    I found the solution.
    for those one who are wondering


    Qt Code:
    1. void MainWindow::on_pushButton_3_clicked()
    2. {
    3. msecond = new Secondwindow(this); //it should be like msecond = new Secondwindow();
    4. msecond->show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by hacquerqop; 17th July 2018 at 12:31.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,141
    Thanks
    235
    Thanked 661 Times in 651 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: New Dialog Problem

    Your code has a memory leak. Each time the button_clicked slot is executed, you create a -new- Secondwindow instance. Unless you delete this later, it creates a memory leak.

    The usual model for creating and displaying dialogs is to create them on the stack, use a call to exec() to show them as modal dialogs, respond to the return value from the dialog, and exit the slot:

    Qt Code:
    1. void MainWindow::on_pushButton_3_clicked()
    2. {
    3. Secondwindow msecond(this);
    4. if ( QDialog::Accepted == msecond.exec() )
    5. {
    6. // do something with the result
    7. }
    8. } // slot exits, second window gets destroyed automatically
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. madal dialog and modeless dialog problem
    By melody:p in forum Qt Programming
    Replies: 0
    Last Post: 25th September 2012, 08:39
  2. Dialog always on top problem
    By zgulser in forum Qt Programming
    Replies: 3
    Last Post: 27th March 2012, 08:42
  3. Problem in resizeing dialog
    By moh.gup@gmail.com in forum Qt Programming
    Replies: 0
    Last Post: 27th April 2010, 14:09
  4. problem in Qt4 dialog
    By grsandeep85 in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2009, 09:57
  5. Problem with resizing dialog
    By Seema Rao in forum Qt Programming
    Replies: 8
    Last Post: 5th May 2006, 17:27

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.