Results 1 to 4 of 4

Thread: send signal from 1 gui to another gui

  1. #1
    Join Date
    Sep 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. #include "ui_dirviewdialog.h"
    2. class MainWindow : public QMainWindow, public Ui::MainWindow
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. MainWindow(QMainWindow *parent = 0);
    8.  
    9. signals:
    10. void close();
    11.  
    12. protected:
    13. void closeEvent(QCloseEvent *event);
    To copy to clipboard, switch view to plain text mode 

    my main cpp code:

    Qt Code:
    1. MainWindow::MainWindow(QMainWindow *parent)
    2. : QMainWindow(parent)
    3. {
    4. setupUi(this);
    5. }
    6. void MainWindow::closeEvent(QCloseEvent *event ){
    7. emit close();
    8. event->accept();
    9. }
    To copy to clipboard, switch view to plain text mode 

    gui that start that main window:
    Qt Code:
    1. #include "ui_serverdialog.h"
    2. class MainWindow;
    3.  
    4. class ServerDialog : public QDialog, public Ui::ServerDialog
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. ServerDialog(QWidget *parent = 0);
    10.  
    11. private slots:
    12. void gui();
    13. void stopgui();
    14.  
    15. private:
    16. MainWindow *mainWindow;
    17. };
    To copy to clipboard, switch view to plain text mode 

    cpp file:

    Qt Code:
    1. #include "serverdialog.h"
    2. #include "dirviewdialog.h"
    3.  
    4.  
    5. ServerDialog::ServerDialog(QWidget *parent)
    6. : QDialog(parent, Qt::WindowMinimizeButtonHint)
    7. {
    8. QWidget::setWindowFlags(Qt::WindowMinimizeButtonHint);
    9. setupUi(this);
    10. stopButton->setEnabled(false);
    11. stopguiButton->setEnabled(false);
    12.  
    13. connect(runButton, SIGNAL(clicked()), this, SLOT(gui()));
    14. connect (mainWindow, SIGNAL(close()), this, SLOT(stopgui()));
    15. }
    16. void ServerDialog::gui()
    17. {
    18.  
    19. mainWindow = new MainWindow;
    20. mainWindow->showMaximized();
    21. mainWindow->activateWindow();
    22. runButton->setEnabled(false);
    23. stopguiButton->setEnabled(true);
    24. }
    25.  
    26. void ServerDialog::stopgui()
    27. {
    28. if(mainWindow != 0){
    29. delete mainWindow;
    30. }
    31. runButton->setEnabled(true);
    32. stopguiButton->setEnabled(false);
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by tho97; 5th December 2007 at 19:52.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: send signal from 1 gui to another gui

    Quote Originally Posted by tho97 View Post
    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().

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  4. #4
    Join Date
    Sep 2007
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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()

Similar Threads

  1. Can you send a signal to a thread?
    By Dumbledore in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2007, 20:31
  2. QAction signal: want to send int
    By vonCZ in forum Newbie
    Replies: 10
    Last Post: 2nd July 2007, 18:52
  3. Manually send signal to slot
    By donmorr in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2006, 15:03
  4. Replies: 2
    Last Post: 17th May 2006, 21:01
  5. send signal from QCombobox
    By raphaelf in forum Qt Programming
    Replies: 22
    Last Post: 28th February 2006, 14:18

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.