rawfool
6th March 2014, 09:00
I have written a function which takes argument as QPushButton pointer, to initialize and apply stylesheet. And later wrote connect statements for the corresponding buttons. On running the application, it is crashing at connect statement. On debugging it's showing segmentation fault. If I comment the connect statements the application runs fine.
If I can see the buttons laid out & also styles applied to them, then why is it giving the segmentation fault error which resembles for unallocated pointers ?
MyWidget::MyWidget(QWidget * parent)
: QWidget(parent)
{
vLyt = new QVBoxlayout;
this->setLayout(vLyt);
addButtons(btn1, "background: green");
addButtons(btn2, "background: white");
addButtons(btn3, "background: black");
addButtons(btn4, "background: blue");
connect(btn1, SIGNAL(clicked(bool)), this, SLOT(mySlot1(bool))); // <<--- In debug mode, it's crashing here
connect(btn2, SIGNAL(clicked(bool)), this, SLOT(mySlot2(bool)));
connect(btn3, SIGNAL(clicked(bool)), this, SLOT(mySlot3(bool)));
connect(btn4, SIGNAL(clicked(bool)), this, SLOT(mySlot4(bool)));
}
void MyWidget::addButtons(QPushButton * pb, QString str)
{
pb = new QPushButton;
pb->setCheckable(true);
pb->setStyleSheet(str);
vLyt->addWidget(pb);
}
Why does the application crash at connect statement ?
If I can see the buttons laid out & also styles applied to them, then why is it giving the segmentation fault error which resembles for unallocated pointers ?
MyWidget::MyWidget(QWidget * parent)
: QWidget(parent)
{
vLyt = new QVBoxlayout;
this->setLayout(vLyt);
addButtons(btn1, "background: green");
addButtons(btn2, "background: white");
addButtons(btn3, "background: black");
addButtons(btn4, "background: blue");
connect(btn1, SIGNAL(clicked(bool)), this, SLOT(mySlot1(bool))); // <<--- In debug mode, it's crashing here
connect(btn2, SIGNAL(clicked(bool)), this, SLOT(mySlot2(bool)));
connect(btn3, SIGNAL(clicked(bool)), this, SLOT(mySlot3(bool)));
connect(btn4, SIGNAL(clicked(bool)), this, SLOT(mySlot4(bool)));
}
void MyWidget::addButtons(QPushButton * pb, QString str)
{
pb = new QPushButton;
pb->setCheckable(true);
pb->setStyleSheet(str);
vLyt->addWidget(pb);
}
Why does the application crash at connect statement ?