c++ - Get TextField->text() from slot Blackberry 10 -


i'm complete beginner in blackberry 10 development. i'm developing app should take user input text box , search if there occurrence of word in text file. i'm using triggered() signal of actionitem invoke search. however, when try fetch user input within slot returns empty string ''. mistake i'm making.

thank in advance.

here code:

main.qml

textfield {         objectname: "anagram"         hinttext: "enter anagram search"         verticalalignment: verticalalignment.center         horizontalalignment: horizontalalignment.center          input {             submitkey: submitkey.done          }             } 

application.cpp

actionitem *main = root->findchild<actionitem*>("search"); bool res1 = qobject::connect(main, signal(triggered()), this, slot(onsearch()));   void applicationui::onsearch() {     qdebug() << "slot activated";     qmldocument *qml = qmldocument::create("asset:///main.qml").parent(this);     abstractpane *root = qml->createrootobject<abstractpane>();     application::instance()->setscene(root);     textfield* query = root->findchild<textfield*>("anagram");     //the string below returns ''     qstring search = query->text();     ... 

introduction

when slot onsearch invoked creating additional ui, unrelated 1 emitted signal.

since there's no default setting text property of anagram, have concluded correct; yield empty string since field freshly created.


solution

you need use root associated current ui (that user has inputted data to), instead of creating new one.

assuming have declared root data-member of applicationui, below you'd expect (and want).

void applicationui::onsearch() {     qdebug() << "slot activated";     textfield* query = root->findchild<textfield*>("anagram");     qstring search = query->text();     // ...  } 

alternative solution

you access current loaded scene (the equivalent of root in snippet) calling scene() on pointer-to abstractpane returned application::instance ():

abstractpane *   current_scene = application::instance ()->scene (); qstring search = current_scene->findchild<textfield*> ("anagram")->text (); 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -