PDA

View Full Version : Linking label mouse info with radio buttons & variables between classes



ebsaith
11th June 2013, 13:41
Good day,
Created class my_label(that creates points from user clicks and draws lines on label) with Help from #Santosh Reddy.

My New Problem:
Created 2 radio buttons on main window that will do different calculations on Qpoints depending of which radio button is checked
1)However those Qpoints are STORED in my_label class, I cant access those QPoints from mainWindow class.

2)Also I Cant test if(radioButton.isChecked()) in the .cpp my_label class since its in mainWindow class.

How do I go about doing this?
(do I use signals and slots -> if so how)

Kind Regards

anda_skoa
11th June 2013, 14:01
Well, one option is to put a setter method into your my_label class and call it from slots in mainWindow that you connect to the radio buttons.

Cheers,
_

Santosh Reddy
11th June 2013, 14:01
1. Write accessor functions in label class to get the points (e.g. getStartPoint(), getEndPoint()...
2. Create a slot in MainWindow class, and connect it to SIGNAL QRadioButton::click() of both radio buttons.
3. In this slot read the status of both radio buttons and based on their status get the points from label using the accessor functions
:)

ebsaith
11th June 2013, 14:37
Kind regards

in testing phase at the moment... will update on successful implementation hopefully.

ebsaith
12th June 2013, 07:39
Normal variables are created in my_qlabel class (point1, point2, result)
If radioButton.Checked() saves it to the corresponding array in mainWindow class

That info is stored in an array(initial point, end point, result)
same for other radio button(initial point, end point, diffCalculationResult) // stored in a different arrays as the 2 arrays will be written to 2 different files

Using getters & setters to send variables(my_qlabel) to arrays(mainWindow) as suggested(thanks)

Please check my code out:
Correct me where need be(most of it)

Created getters and setters in my_qlabel class


int my_qlabel::getStartPoint()
{
return x1;
}

int my_qlabel::getEndPoint()
{
return y1;
}


int my_qlabel::getOrientation()
{
return theta;
}


RadioButtons: radioButton_1, radioButton_2

my connect statement


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




void Dialog::getInfo()
{
if(ui->radioButton_1->clicked(true))
{
reCounter += 1;
reX[reCounter] = my_qlabel::getStartPoint();
reY[reCounter] = my_qlabel::getEndPoint();
reO[reCounter] = my_qlabel::getOrientation();
radioButton_1->setChecked(false);
}
else if(ui->radioButton_1->clicked(true))
{


when Build -> 10 errors
1) QAbstractButton::clicked(bool) is protected
2)radioButtons 1& 2 not declared -> they are!
3)error in if statement with regards to radioButton
4) cannot call member functions of my_qlabel with out object


reX[reCounter] = my_qlabel::getStartPoint();
... in if statement above



help!

anda_skoa
12th June 2013, 09:28
1) QAbstractButton::clicked(bool) is protected

That is a signal, you are looking for isChecked()

2)radioButtons 1& 2 not declared -> they are!

No, they are not. ui->radioButton_1 and _2 are


3)error in if statement with regards to radioButton

Probably a follow up error because of (1)



4) cannot call member functions of my_qlabel with out object

You try to access a method on the class instead of the instance of the label.

Cheers,
_

ebsaith
12th June 2013, 09:36
How do i check if radio Button is checked from a different class

radio Button is in mainWindow class!
need to check from my_label class!

thanks