Results 1 to 3 of 3

Thread: error opening a new dialog on button click

  1. #1
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default error opening a new dialog on button click

    I am trying to open a new dialog from a button click inside the mainwindow.
    My code is as follows:
    Qt Code:
    1. void MainWindow::on_btn_login_clicked()
    2. {
    3. if (count == 1)
    4. {
    5. dialog->show();
    6. dialog->raise();
    7. dialog->activateWindow();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    My Mainwindow .h is as follows:
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include "dialog.h"
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18. private slots:
    19. void on_btn_magnifier_clicked();
    20.  
    21. void on_btn_login_clicked();
    22. private:
    23. Ui::MainWindow *ui;
    24. Dialog *dialog;
    25. };
    26.  
    27. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    I have made a new form named dialog.ui with dialog.cpp and dialog.h
    When i am debugging the application,segmentation fault is coming on the line:
    Qt Code:
    1. dialog->show();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,459
    Thanked 271 Times in 266 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error opening a new dialog on button click

    Pointer dialog is not initialized.

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

    prkhr4u (25th November 2013)

  4. #3
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error opening a new dialog on button click

    Thank you.
    added this to btn_login_clicked:
    Qt Code:
    1. Dialog *dialog=new Dialog();
    To copy to clipboard, switch view to plain text mode 

    Now everything working and i am able to open a new window on the button click

Similar Threads

  1. Replies: 1
    Last Post: 20th March 2013, 19:38
  2. Replies: 2
    Last Post: 26th April 2011, 11:44
  3. Qt 4.6.0: Opening a dialog from a main window
    By dmginc in forum Qt Programming
    Replies: 3
    Last Post: 14th January 2010, 12:16
  4. QInput dialog is always opening twice
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 13th November 2009, 12:46
  5. Opening a Dialog from a MainWindow FileMenu
    By nbkhwjm in forum Newbie
    Replies: 4
    Last Post: 17th April 2007, 12:24

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.