10-08-2013 06:32 AM
I have three textfields in qml file. After submitting the data according to the web service response I need to set the focus on the particular textfield from cpp file. As my textfields are in qml I am not able to place focus on particular textfield from cpp.
I am not able to use requestFocus() function in cpp.
Please help me..
10-08-2013 06:38 AM
You can use the findChild() method to locate the approproiate TextField and then call the requestFocus function...
10-08-2013 06:44 AM
yes, I have used findChild() to get textfield object but not able to call requestFocus function.
QmlDocument *qml = QmlDocument::create("asset:///Register.qml"); AbstractPane *root = qml->createRootObject<AbstractPane>(); QObject *textfield = root->findChild<QObject*>("phone");
10-08-2013 06:47 AM - edited 10-08-2013 06:50 AM
Because requestFocus does not reside in the QObject class it resides in the control class!
Change QObject to TextField in your findChild call;
TextField* textfield = root->findChild<TextField*>("phone"); textField->requestFocus();
Make sure you are correctly setting the UI controls objectName as well.
10-08-2013 07:49 AM
still not able to place the focus. Do I need to use setScene() function. But wile using setScene() my page get refresh and all textfields are empty.
current code is
QmlDocument *qml = QmlDocument::create("asset:///Register.qml"); qml->setContextProperty("RoamAssist",this); AbstractPane *root = qml->createRootObject<AbstractPane>(); TextField* textfield = root->findChild<TextField*>("ph"); textfield->requestFocus();
What can I do?
10-08-2013 08:01 AM
Please check to see that the findChild function is returning an object, I would bet large amounts of money it is returning null.
If this is the case then you have either not set your objectName correctly or the object is not in the scene graph at the time you are doing the call.
10-16-2013 06:26 AM
Using findChild I am able to get the textfield but not able to display those chages on screen. If I use setScence() function then hole page is reloaded and previous entered values are gone.
How can I set focus to textfield?