You can't connect signals and slots where the slot has more arguments than the signal.
This would mean that some data needs to come from thin air.
This means that the following is not possible:
connect(pushbutton, SIGNAL(clicked()), lineedit, SLOT(copyText()));
connect(pushbutton, SIGNAL(clicked()), lineedit, SLOT(copyText()));
To copy to clipboard, switch view to plain text mode
Instead, create a slot like this:
public slots:
void slotButtonClicked();
public slots:
void slotButtonClicked();
To copy to clipboard, switch view to plain text mode
This slots has maximum the same amount and the same type of arguments as the signal. In this case the clicked() signal of the button.
To connect them, write:
connect(pushbutton, SIGNAL(clicked()), this, SLOT(slotButtonClicked());
connect(pushbutton, SIGNAL(clicked()), this, SLOT(slotButtonClicked());
To copy to clipboard, switch view to plain text mode
Make sure that at least the QLineEdit is available in the whole myCanvas class.
But a general rule is to manage all your pointers, otherwise you might get into trouble.
Thus in your class definition do this:
private:
private:
QLineEdit* lineedit;
QPushButton* pushbutton;
To copy to clipboard, switch view to plain text mode
In the implementation you'll get something like:
myCanvas
::myCanvas(QWidget* parent
) : QWidget(parent
) // You might also want to pass the flags to the base class.{
... // other code maybe
... // other code maybe, like the connection of the signal and slot, the layout, ...
}
myCanvas::myCanvas(QWidget* parent) : QWidget(parent) // You might also want to pass the flags to the base class.
{
... // other code maybe
lineedit = new QLineEdit(this);
pushbutton = new QPushButton("Enter", this);
... // other code maybe, like the connection of the signal and slot, the layout, ...
}
To copy to clipboard, switch view to plain text mode
Now that the signal/slot connection is right and the widgets are available in the whole class, you can implement the slot:
void myCanvas::slotButtonClicked()
{
QString theText
= lineedit
->text
();
}
void myCanvas::slotButtonClicked()
{
QString theText = lineedit->text();
}
To copy to clipboard, switch view to plain text mode
You use the line edit inside the slot connected to the button clicked signal.
Bookmarks