View Full Version : Program crashes when radioButton selected

12th June 2013, 10:47
when I click any of the radioButons displayed in my mainWindow... runtime error program crashes(pic att)

This is my connect statement in constructor of main class

connect(ui->radioButton_1, SIGNAL(clicked()), this, SLOT(getInfo()));
connect(ui->radioButton_2, SIGNAL(clicked()), this, SLOT(getInfo()));

Slot: getInfo
void Dialog::getInfo()
my_qlabel alpha; // create an instance of class my_qlabel to access public member variables

reCounter += 1;
reX[reCounter] = alpha.x1;
reY[reCounter] = alpha.y1;
reO[reCounter] = alpha.theta;
else if ...

Not sure if the connect statement is causing the crash or the if statement

please help
Kind Regards

12th June 2013, 15:18
Did you try running in a debugger and printing the stack trace after the crash? Should point you to the offending line...

12th June 2013, 20:58
what is the size of reX , reY and reO ?? and what is the initial value of the reCounter

12th June 2013, 22:16
are your pointers initialised?

13th June 2013, 06:18
Make sure that your GUI is initiated before connect statement.

Post your class code, there will be some hidden mistakes.

13th June 2013, 09:16
Done some modifying on code... to no avail though

Basically I need to check which radio button selected
The Problem -> RadioButton in main dialog Class(Window)
-> the Check statement is in a different class("label class" within Window/dialog)

Created signals & slots as:

Dialog::Dialog(QWidget *parent) :
ui(new Ui::Dialog)
connect(ui->radioButton_1, SIGNAL(n1_Selected()), my_qlabel, SLOT(my_qlabel::HandleN1()));
connect(ui->radioButton_2, SIGNAL(n2_Selected()), my_qlabel, SLOT(my_qlabel::HandleN2()));

in dialog:

void Dialog::on_radioButton_1_clicked()
emit n1_Selected();

void Dialog::on_radioButton_2_clicked()
emit n2_Selected();

my slots in sub class (label class)

private slots:
void HandleN1();
void HandleN2();


void my_qlabel::HandleN1()

void my_qlabel::HandleN2()

Above not working!
Where am I going wrong?
How do I fix it?


13th June 2013, 09:25
As i have seen some issues in your code implementation.

// Make sure my_qlabel is is initialized before you use.

my_qlabel = new QLabel(this); // my_qlabel is not initialized in your code

// ui->radioButton_1 should be 'this' because you are emitting a signal from dialog class
connect(ui->radioButton_1, SIGNAL(n1_Selected()), my_qlabel, SLOT(HandleN1()));

// ui->radioButton_2 should be 'this' because you are emitting a signal from dialog class
connect(ui->radioButton_2, SIGNAL(n2_Selected()), my_qlabel, SLOT(HandleN2()));

Try changing these things...


13th June 2013, 09:55
Thanks, simple as that :)

16th June 2013, 03:28
No, not as simple as that. Do you want to create a *new* QLabel every time a radio button is clicked? That is what is now happening if you modified your code to follow the previous answer. Those new QLabel instances have no relationship at all to any QLabel that might be in your GUI they are simply dangling my_qlabel pointers that will eventually get deleted when the main window goes out of scope.