1

I have a programm with a QLabel, QTextEdit and a QPushButton.

I want to put the text from LineEdit to Label when I click the button.

I can do that by creating my own slot but can it be done with Qt slots?

I've tried this code but it works not as I want...

this->connect(pushButton ,SIGNAL(clicked()), lineEdit, SIGNAL(textChanged(QString)), Qt::QueuedConnection);
t->connect(lineEdit, SIGNAL(textChanged(QString)) , label ,SLOT(setText(QString)), Qt::DirectConnection);

2 Answers 2

1

If you need to force the user to push a QButton for "applying" the text he/she typed in a QTextEdit to a QLabel, maybe you want to check the validity of the inserted text, or use the text to achieve some goal or to store it in a variable for later use... so you need a custom slot or a custom class.

Instead you can connect the signal QTextEdit.textChanged(QString) to the slot QLabel.setText(QString), so everything is typed in the QTextEdit is sent to the QLabel without pushing a button.

But all depends on your aim.

1
  • I know but it's not what i want. I am just wondering if it's posiible do it my way... Commented Apr 8, 2015 at 17:32
1

Here's how I would do it:

connect(ui->pushbutton, SIGNAL(clicked()), this, SLOT(slot_pushbutton_clicked()))

And then in the the slot_pushbutton_clicked slot,

ui->label->setText(ui->lineEdit->text)

Hope it helps :)

Not the answer you're looking for? Browse other questions tagged or ask your own question.