Results 1 to 7 of 7

Thread: Linking label mouse info with radio buttons & variables between classes

  1. #1
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Question 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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    ebsaith (11th June 2013)

  4. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    ebsaith (11th June 2013)

  6. #4
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default 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.

  7. #5
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Post 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
    Qt Code:
    1. int my_qlabel::getStartPoint()
    2. {
    3. return x1;
    4. }
    5.  
    6. int my_qlabel::getEndPoint()
    7. {
    8. return y1;
    9. }
    10.  
    11.  
    12. int my_qlabel::getOrientation()
    13. {
    14. return theta;
    15. }
    To copy to clipboard, switch view to plain text mode 

    RadioButtons: radioButton_1, radioButton_2

    my connect statement
    Qt Code:
    1. connect(ui->radioButton_1, SIGNAL(clicked()), this, SLOT(getInfo()));
    2. connect(ui->radioButton_1, SIGNAL(clicked()), this, SLOT(getInfo()));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Dialog::getInfo()
    2. {
    3. if(ui->radioButton_1->clicked(true))
    4. {
    5. reCounter += 1;
    6. reX[reCounter] = my_qlabel::getStartPoint();
    7. reY[reCounter] = my_qlabel::getEndPoint();
    8. reO[reCounter] = my_qlabel::getOrientation();
    9. radioButton_1->setChecked(false);
    10. }
    11. else if(ui->radioButton_1->clicked(true))
    12. {
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. reX[reCounter] = my_qlabel::getStartPoint();
    2. ... in if statement above
    To copy to clipboard, switch view to plain text mode 


    help!
    Last edited by ebsaith; 12th June 2013 at 09:06. Reason: updated contents

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Linking label mouse info with radio buttons & variables between classes

    Quote Originally Posted by ebsaith View Post
    1) QAbstractButton::clicked(bool) is protected
    That is a signal, you are looking for isChecked()
    Quote Originally Posted by ebsaith View Post
    2)radioButtons 1& 2 not declared -> they are!
    No, they are not. ui->radioButton_1 and _2 are

    Quote Originally Posted by ebsaith View Post
    3)error in if statement with regards to radioButton
    Probably a follow up error because of (1)

    Quote Originally Posted by ebsaith View Post
    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,
    _

  9. #7
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Post 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
    Last edited by ebsaith; 12th June 2013 at 11:06. Reason: updated contents

Similar Threads

  1. QTableWidget radio buttons
    By Pettson in forum Newbie
    Replies: 4
    Last Post: 15th December 2011, 09:51
  2. Non editable Radio Buttons
    By babu198649 in forum Newbie
    Replies: 9
    Last Post: 11th November 2009, 11:48
  3. Replies: 2
    Last Post: 11th August 2009, 16:01
  4. array of radio buttons
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2006, 12:59
  5. How to get larger radio buttons on XP?
    By Ben.Hines in forum Qt Programming
    Replies: 9
    Last Post: 24th April 2006, 19:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.