Linking label mouse info with radio buttons & variables between classes
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
Re: Linking label mouse info with radio buttons & variables between classes
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,
_
Re: Linking label mouse info with radio buttons & variables between classes
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
:)
Re: Linking label mouse info with radio buttons & variables between classes
Kind regards
in testing phase at the moment... will update on successful implementation hopefully.
Re: Linking label mouse info with radio buttons & variables between classes
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
Code:
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
Code:
connect(ui->radioButton_1, SIGNAL(clicked()), this, SLOT(getInfo()));
connect(ui->radioButton_1, SIGNAL(clicked()), this, SLOT(getInfo()));
Code:
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
Code:
reX[reCounter] = my_qlabel::getStartPoint();
... in if statement above
help!
Re: Linking label mouse info with radio buttons & variables between classes
Quote:
Originally Posted by
ebsaith
1) QAbstractButton::clicked(bool) is protected
That is a signal, you are looking for isChecked()
Quote:
Originally Posted by
ebsaith
2)radioButtons 1& 2 not declared -> they are!
No, they are not. ui->radioButton_1 and _2 are
Quote:
Originally Posted by
ebsaith
3)error in if statement with regards to radioButton
Probably a follow up error because of (1)
Quote:
Originally Posted by
ebsaith
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,
_
Re: Linking label mouse info with radio buttons & variables between classes
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