FindComponent in Qt?
-
The code you're looking at is from a form I created using Lazarus (Object Pascal).
On that form, I have 20 Textboxes (AMC_Edit1 thru AMC_Edit20), 80 RadioButtons (AMC_RadioButton1 thru AMC_RadioButton80).
This bit of code uses FindComponent to find the Textboxes and RadioButtons, which allows me to loop thru them.
My concern is whether or not Qt has something similar.
var i, j, k : Integer; rcbc, tec: TComponent; begin j := 1; for i := 1 to 20 do begin tec := Form1.FindComponent('AMC_Edit' + IntToStr(i)); if tec is TEdit then for k := 1 to 4 do begin rcbc := Form1.FindComponent('AMC_RadioButton' + IntToStr(j)); Inc(j); if ((tec as TEdit).Text = (rcbc as TRadioButton).Caption) and (rcbc as TRadioButton).Checked then begin (rcbc as TRadioButton).Font.Color := clLime; end; end; end; end;
-
@Driftwood
You can use QObject::findChildren() for this. You can search by type and/or by name. -
Hi,
Look at findChild.
Note that you might be able make the logic simpler by first checking what Qt has to offer like signals and slots.
You should rather write down what should happen and then look if there's a simpler way than looping through all the components.
-
@SGaist said in FindComponent in Qt?:
Hi,
Look at findChild.
Note that you might be able make the logic simpler by first checking what Qt has to offer like signals and slots.
You should rather write down what should happen and then look if there's a simpler way than looping through all the components.
I'll do that, SGaist. I'm off and on with Qt, always falling back Lazarus (so easy to use). But Qt, I'm seeing time and again, is just as capable. I do need to study Signals/Slots, though.