I have a text field and a button purely designed in c++(without importing a qml doc). How do i read the text from the text field when I click the buton.
I am unable to find a function associated for that.
I have a text field and a button purely designed in c++(without importing a qml doc). How do i read the text from the text field when I click the buton.
I am unable to find a function associated for that.
To hook up the button to a method, use the following code:
button = new Button();
texField = new TextField();
connect(button, SIGNAL(clicked()), this, SLOT(onClicked());
Then define the onClicked
slot as so:
void ClassName::onClicked() {
qDebug() << textField->text(); //print the textField's text
}
For this to work, this method has to be marked in the class as a Q_SLOT
and the object itself must be marked as a Q_OBJECT
.