PDA

View Full Version : closing dialog window



sksingh73
21st June 2010, 19:12
I am making a program, which has got a main window. It will have two push buttons, when i push first button, it will open another dialog wondow say hashchain. and when i press second button second dialog window will open say communication. i requires that when i close child dialog window say hashchain, my mainwindow should not close. but i am facing a unique problem. when i open hashchain window & closes it, it also closes main window. whereas when i closes communication window, it closes without closing main window, but when i closes main window, communication window again pops up. please help. my code is

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
#include "hashchain.h"
#include "client.h"
class mainwindow : public QDialog, public Ui::mainDialog
{
Q_OBJECT
public:
mainwindow(QWidget *parent = 0);
private slots:
void on_generateButton_clicked();
void on_comnButton_clicked();
private:
hashchain *hash;
client *cli;
};
#endif // MAINWINDOW_H

mainwindow.cpp

#include <QtGui>
#include "mainwindow.h"
#include "hashchain.h"
#include "client.h"
mainwindow::mainwindow(QWidget *parent) : QDialog(parent)
{
setupUi(this);
connect( generatechainButton, SIGNAL( clicked() ), this, SLOT( on_generateButton_clicked() ) );
connect( comnButton, SIGNAL( clicked() ), this, SLOT( on_comnButton_clicked() ) );
hash = 0;
cli = 0;
}

void mainwindow::on_generateButton_clicked()
{
if (!hash) {
hash = new hashchain(this);

}
hash->show();
hash->activateWindow();
}

void mainwindow::on_comnButton_clicked()
{
if (!cli) {
cli = new client(this);
}
cli->show();
cli->activateWindow();
}

waynew
21st June 2010, 22:27
I have a main window application with many dialogs and no problems, but my code looks like this:



class MainWindow : public QMainWindow
{
Q_OBJECT
// and more




MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
// and more


Could be your declarations are giving you the trouble.