0

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.

Richard
  • 8,920
  • 2
  • 18
  • 24
DesirePRG
  • 6,122
  • 15
  • 69
  • 114

1 Answers1

3

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.

Konrad Lindenbach
  • 4,911
  • 1
  • 26
  • 28