send signal from 1 gui to another gui
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:
Code:
#include "ui_dirviewdialog.h"
class MainWindow
: public QMainWindow,
public Ui
::MainWindow{
Q_OBJECT
public:
signals:
void close();
protected:
my main cpp code:
Code:
{
setupUi(this);
}
emit close();
event->accept();
}
gui that start that main window:
Code:
#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;
};
cpp file:
Code:
#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);
}
Re: send signal from 1 gui to another gui
Quote:
Originally Posted by
tho97
connect (mainWindow, SIGNAL(close()), this, SLOT(stopgui()));
You don't initialize mainWindow. Another problem is that you should create that connection for every new MainWindow object you create. So the easiest solution is to move this line to ServerDialog::gui().
Re: send signal from 1 gui to another gui
You create the mainWindow object after you connect it to your slot. So at the time of connect, you have an invalid pointer there.
Try either creating the object before connect, or moving the connect in the function where you create the window.
Re: send signal from 1 gui to another gui
thank you, it solved my segment fault and work now after I move connect to gui()