Results 1 to 9 of 9

Thread: To connect principal window with a second one

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default To connect principal window with a second one

    Greetings to all of you!
    I am facing a problem of connecting a parent window with a children one. I have successfully implemented each window as well as their respectives widgets, but the slots of the children window does not work.
    Here is my code:

    Qt Code:
    1. #ifndef DEF_ESSAIE
    2. #define DEF_ESSAIE
    3.  
    4. #include <QtGui>
    5.  
    6. class Essaie: public QMainWindow
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. Essaie();
    12. ~Essaie();
    13.  
    14. private slots:
    15. void ouvrirFenetre1();
    16.  
    17.  
    18. private:
    19. QMainWindow *m_fenetrePrincipale;
    20. QPushButton *m_butonFenetre1;
    21.  
    22. };
    23. #endif // ESSAIE_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef DEF_FENETRE1
    2. #define DEF_FENETRE1
    3.  
    4. #include<QtGui>
    5.  
    6. class Fenetre1: public QMainWindow
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. Fenetre1(QWidget *parent);
    12. ~Fenetre1();
    13.  
    14. private slots:
    15.  
    16. void displayList();
    17.  
    18. private:
    19. QWidget *m_fenetre1;
    20. QPushButton *m_butonFermer;
    21.  
    22. };
    23. #endif // FENETRE1_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "Essaie.h"
    2. #include "Fenetre1.h"
    3.  
    4.  
    5. Essaie::Essaie()
    6. {
    7. m_fenetrePrincipale = new QMainWindow;
    8. m_fenetrePrincipale->setFixedSize(300, 200);
    9.  
    10.  
    11. m_butonFenetre1 = new QPushButton("Ouvrir", this);
    12. m_butonFenetre1->move(75, 100);
    13.  
    14.  
    15. connect(m_butonFenetre1, SIGNAL(clicked()), this, SLOT(ouvrirFenetre1()));
    16.  
    17. }
    18.  
    19. void Essaie::ouvrirFenetre1()
    20. {
    21. Fenetre1 *fene = new Fenetre1(this);
    22. fene->show();
    23.  
    24. }
    25.  
    26. Essaie::~Essaie()
    27. {}
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "Fenetre1.h"
    2.  
    3. Fenetre1::Fenetre1(QWidget *parent = 0): QMainWindow(parent)
    4. {
    5. this->setFixedSize(200, 150);
    6. this->setWindowTitle("Fenetre1");
    7.  
    8. m_butonFermer = new QPushButton("Fermer", this);
    9.  
    10. connect(m_butonFermer, SIGNAL(clicked()), this, SLOT(close()));
    11. connect(m_butonDisplay, SIGNAL(clicked()), this, SLOT(displayList()));
    12.  
    13. }
    14.  
    15. Fenetre1::~Fenetre1()
    16. {}
    To copy to clipboard, switch view to plain text mode 

    On the children window, the closing slot is working properly, but not that of display.
    I would be greatfull to you if you could help me overcoming this problem.
    Many thanks in advance!
    Last edited by wysota; 27th March 2012 at 18:14.

Similar Threads

  1. Replies: 6
    Last Post: 9th November 2011, 04:31
  2. connect window's close button
    By ahmetturan in forum Newbie
    Replies: 3
    Last Post: 12th July 2011, 07:50
  3. Replies: 2
    Last Post: 9th May 2011, 10:38
  4. Replies: 0
    Last Post: 8th March 2011, 22:08
  5. [PyQt4] Want to connect a window's close button
    By Dodle in forum Qt Programming
    Replies: 7
    Last Post: 21st April 2010, 11:13

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
  •  
Qt is a trademark of The Qt Company.