Connecter un slot du widget parent
Hello,
Je tente de connecter un slot se trouvant dans le widget 'conteneur', à partir d'un signal du widget 'child' :
Code:
connect(toggleBigSmall, SIGNAL(clicked()),this->parentWidget(), SLOT(hideOthers(SubWindow&)));
J'ai le message suivant :
Code:
QObject::connect: Cannot connect QPushButton::clicked() to (null)::hideOthers(SubWindow&)
Que fais-je faux !
Il faut dire que je suis très débutant.
A+
Gilles
Connecter un slot du widget parent
Hello,
Je tente de réaliser la connection d'un signal du widget 'Child' au slot du widget 'Parent', ce en utilisant parentWidget().
L'instruction parentWidget() me retourne null.
D'ou l'erreur :
QObject::connect: Cannot connect SubWindow::clicked(SubWindow&) to (null)::hideOthers(SubWindow&)
Pourquoi ?
Comment faire ?
Merci pour vos réponses !
Gilles
Implémentation du 'child' :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <QtGui>
#include "glwidget.h"
#include "subWindow.h"
//! [0]
SubWindow::SubWindow()
{
glwidget = new GLWidget();
groupeBouton=new QGroupBox();
groupeBouton->setMaximumWidth(80);
scrollVertical=new QScrollBar();
scrollVertical->setOrientation(Qt::Vertical);
scrollHorizontal=new QScrollBar();
scrollHorizontal->setOrientation(Qt::Horizontal);
toggleBigSmall=new QPushButton(groupeBouton);
connect(this, SIGNAL(clicked(SubWindow&)),this->parentWidget(), SLOT(hideOthers(SubWindow&)));
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(glwidget,0,0);
mainLayout->addWidget(scrollVertical,0,1);
mainLayout->addWidget(groupeBouton,0,2);
mainLayout->addWidget(scrollHorizontal,1,0);
setLayout(mainLayout);
setWindowTitle(tr("AutoCalc"));
} |
Ici, l'implémentation du widget parent :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <QtGui>
#include "glwidget.h"
#include "window.h"
Window::Window()
{
profil=new SubWindow();
single = new SubWindow();
compound =new SubWindow();
machining = new SubWindow();
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(profil,0,0);
mainLayout->addWidget(single,0,1);
mainLayout->addWidget(compound,1,1);
mainLayout->addWidget(machining,1,0);
setLayout(mainLayout);
setWindowTitle(tr("AutoCalc"));
//qDebug() << "Parent: " << profil->parentWidget();
}
void Window::hideOthers(SubWindow& monsub){
monsub.hide();
} |