When the button is pressed, it doesn't copy the LineEdit in Label.
-
My_Window::My_Window(QWidget *parent) : QWidget(parent) { QPushButton *set_text_button=new QPushButton(this); QLabel *text_label=new QLabel(this); QLineEdit *line_edit=new QLineEdit(this); QHBoxLayout *main_layout=new QHBoxLayout(this); set_text_button->setText("Set Text"); text_label->setText("0"); line_edit->setText("0"); main_layout->addWidget(set_text_button); main_layout->addWidget(line_edit); main_layout->addWidget(text_label); temp_text=line_edit->text(); QObject::connect(set_text_button,SIGNAL(clicked(bool)),this,SLOT(slot_send_text())); QObject::connect(this,SIGNAL(signal_send_text(QString)),text_label,SLOT(setText(QString))); setWindowTitle("Changing text on label"); } void My_Window::slot_send_text() { emit (signal_send_text(temp_text)); }
When the button is pressed, the label-a text should be the same as the lineedit-a text, but somehow it doesn't happen.
-
Where's your elephant?
slot_send_text()
Is the variable temp_text? Try to rewrite the slot as follows:emit (signal_send_text(line_edit->text()));
Or so (may be clearer):
temp_text = line_edit->text(); emit (signal_send_text(temp_text));