PDA

View Full Version : connect problem



liengen
22nd October 2008, 14:28
Hi!
Having a problem to connect a qlabel and qpushbutton.
Here`s some code:


QLineEdit *lineEdit = new QLineEdit;
QLabel *copied = new QLabel;
QPushButton *copy = new QPushButton("&Copy");

QDialog::connect(copy, SIGNAL(clicked()), copied, SLOT(setText(lineEdit->text())));
QDialog::connect(copy, SIGNAL(clicked()), lineEdit, SLOT(clear()));


The first connect sentence isnt working. I`ve tried with setText("foobar"), but even then nothing happens with the label

spirit
22nd October 2008, 14:41
you must write slot for this.
corrent code


...
connect(copy, SIGNAL(clicked()), this, SLOT(paste()));
...

void MyWidget::pate()
{
copied->setText(lineEdit->text());
}

in connect you must describe signature of methods, but don't set real parameters. read this and you will find all answers Signals and Slots (http://doc.trolltech.com/4.4/signalsandslots.html)

liengen
22nd October 2008, 16:21
Ah wonderful! This threw some light over the problem

Thanks! :D