Quote Originally Posted by ChrisW67 View Post
Make up your mind. One moment you list all children, then actually want all descendants, then complain that findChildren() requires an object name, and when told it does not complain that you want to extract a widget by object name.
Locating a single object using the generic findChildren() has nothing to do with displaying the dynamically loaded form. Your code above does nothing like displaying the form. If you want to do that you follow the simple pattern in the documentation for QUiLoader. Load the form and insert the resulting widget into the layout of your program.
Ok. May be this is because I did not explain my requirement.

First I wanted to create a generic loader program which will load any form. Till this I was done. I used the basic example in the QUiLoader example and did it.
Now I want to take user input from this dynamically loaded form. (So if user types something into the line edit then take that input, etc.) But the QUiLoader class does not give direct access to the pointers of the widgets it creates while loading the form (these are private variables plus it doesnt store them.) We can create instances in our program by using object names which my function, as it is generic, wont have it. So first I get the object names, then the base classes of all widgets to create the references of to widgets.
So I tried to get the object names as follows as u suggested:

Qt Code:
  1. QList<QWidget *> list = form->findChildren<QWidget *>()
  2.  
  3. for(i = 0; i < list.size(); i++)
  4. {
  5. QString name = list.at(i)->objectName();
  6. qDebug() <<"object"<< i <<" = "<< qPrintable(name);
  7. }
To copy to clipboard, switch view to plain text mode 

It was good for many widgets. But for some widgets (I think the containers) it gives even the widgets inside them like follows:

Qt Code:
  1. object 96 = textEdit
  2. object 97 = qt_scrollarea_viewport
  3. object 98 = qt_scrollarea_hcontainer
  4. object 99 =
  5. object 100 = qt_scrollarea_vcontainer
  6. object 101 =
  7. object 102 = plainTextEdit
  8. object 103 = qt_scrollarea_viewport
  9. object 104 = qt_scrollarea_hcontainer
  10. object 105 =
  11. object 106 = qt_scrollarea_vcontainer
  12. object 107 =
  13. object 108 = spinBox
  14. object 109 = qt_spinbox_lineedit
  15. object 110 = doubleSpinBox
  16. object 111 = qt_spinbox_lineedit
  17. object 112 = timeEdit
  18. object 113 = qt_spinbox_lineedit
To copy to clipboard, switch view to plain text mode 

This is a problem.
Once I find a way out of this I can use widget.inherits("") to find the base class and then create the reference.

That is what the form tab order, set in the Designer, is for. The order the focus moves "naturally" around the form is how the user might enter the data. It has no bearing on the order they actually enter the data or the order in which you can access the widget content.
Also after taking the user input I want to send this to some other machine in form of packet. This is the sole reason I am worried about the order of widgets in the form because I will send the values in that order only. So no comples protocol needs to be established.

You are expecting a QMindReadingFormHandler class so you do not have to do the work. There is no such beast.
Well this is bad. Sorry if I annoyed you.


Here is a complete example.
Thank you very much for the code. It is useful.