Hi,
I try to send a signal from my main gui window (when it closes) to another gui ( which start that main window gui). How I can do it?
I got a segment fault when I try this code
main window header:
#include "ui_dirviewdialog.h"
class MainWindow
: public QMainWindow,
public Ui
::MainWindow{
Q_OBJECT
public:
signals:
void close();
protected:
#include "ui_dirviewdialog.h"
class MainWindow : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
MainWindow(QMainWindow *parent = 0);
signals:
void close();
protected:
void closeEvent(QCloseEvent *event);
To copy to clipboard, switch view to plain text mode
my main cpp code:
{
setupUi(this);
}
emit close();
event->accept();
}
MainWindow::MainWindow(QMainWindow *parent)
: QMainWindow(parent)
{
setupUi(this);
}
void MainWindow::closeEvent(QCloseEvent *event ){
emit close();
event->accept();
}
To copy to clipboard, switch view to plain text mode
gui that start that main window:
#include "ui_serverdialog.h"
class MainWindow;
class ServerDialog
: public QDialog,
public Ui
::ServerDialog{
Q_OBJECT
public:
private slots:
void gui();
void stopgui();
private:
MainWindow *mainWindow;
};
#include "ui_serverdialog.h"
class MainWindow;
class ServerDialog : public QDialog, public Ui::ServerDialog
{
Q_OBJECT
public:
ServerDialog(QWidget *parent = 0);
private slots:
void gui();
void stopgui();
private:
MainWindow *mainWindow;
};
To copy to clipboard, switch view to plain text mode
cpp file:
#include "serverdialog.h"
#include "dirviewdialog.h"
ServerDialog
::ServerDialog(QWidget *parent
) : QDialog(parent, Qt
::WindowMinimizeButtonHint) {
QWidget::setWindowFlags(Qt
::WindowMinimizeButtonHint);
setupUi(this);
stopButton->setEnabled(false);
stopguiButton->setEnabled(false);
connect(runButton, SIGNAL(clicked()), this, SLOT(gui()));
connect (mainWindow, SIGNAL(close()), this, SLOT(stopgui()));
}
void ServerDialog::gui()
{
mainWindow = new MainWindow;
mainWindow->showMaximized();
mainWindow->activateWindow();
runButton->setEnabled(false);
stopguiButton->setEnabled(true);
}
void ServerDialog::stopgui()
{
if(mainWindow != 0){
delete mainWindow;
}
runButton->setEnabled(true);
stopguiButton->setEnabled(false);
}
#include "serverdialog.h"
#include "dirviewdialog.h"
ServerDialog::ServerDialog(QWidget *parent)
: QDialog(parent, Qt::WindowMinimizeButtonHint)
{
QWidget::setWindowFlags(Qt::WindowMinimizeButtonHint);
setupUi(this);
stopButton->setEnabled(false);
stopguiButton->setEnabled(false);
connect(runButton, SIGNAL(clicked()), this, SLOT(gui()));
connect (mainWindow, SIGNAL(close()), this, SLOT(stopgui()));
}
void ServerDialog::gui()
{
mainWindow = new MainWindow;
mainWindow->showMaximized();
mainWindow->activateWindow();
runButton->setEnabled(false);
stopguiButton->setEnabled(true);
}
void ServerDialog::stopgui()
{
if(mainWindow != 0){
delete mainWindow;
}
runButton->setEnabled(true);
stopguiButton->setEnabled(false);
}
To copy to clipboard, switch view to plain text mode
Bookmarks