PDA

View Full Version : error opening a new dialog on button click



prkhr4u
25th November 2013, 07:27
I am trying to open a new dialog from a button click inside the mainwindow.
My code is as follows:

void MainWindow::on_btn_login_clicked()
{
if (count == 1)
{
dialog->show();
dialog->raise();
dialog->activateWindow();
}
}
My Mainwindow .h is as follows:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "dialog.h"
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:
void on_btn_magnifier_clicked();

void on_btn_login_clicked();
private:
Ui::MainWindow *ui;
Dialog *dialog;
};

#endif // MAINWINDOW_H


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:

dialog->show();

Lesiok
25th November 2013, 07:47
Pointer dialog is not initialized.

prkhr4u
25th November 2013, 08:15
Thank you.
added this to btn_login_clicked:

Dialog *dialog=new Dialog();

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