Let's say you have a class called Window which contains those line edits.
You would begin with declaring a new custom slot:
class Window : public WhatEver
{
Q_OBJECT // <---
public:
[...]
private slots:
void copy(); // <---
};
class Window : public WhatEver
{
Q_OBJECT // <---
public:
[...]
private slots:
void copy(); // <---
};
To copy to clipboard, switch view to plain text mode
Then, instead of connecting to each line edit's copy(), you would connect to this custom slot we declared above:
connect(action_Copy,SIGNAL(triggered()),this,SLOT(copy()));
connect(action_Copy,SIGNAL(triggered()),this,SLOT(copy()));
To copy to clipboard, switch view to plain text mode
Finally, you would implement the custom slot. More or less something like this:
void Window::copy()
{
// get the last child widget which has focus and
// try to cast it as line edit
QLineEdit* lineEdit
= dynamic_cast<QLineEdit
*>
(focusWidget
());
if (lineEdit)
{
// it was a line edit, perform copy
lineEdit->copy();
}
}
void Window::copy()
{
// get the last child widget which has focus and
// try to cast it as line edit
QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(focusWidget());
if (lineEdit)
{
// it was a line edit, perform copy
lineEdit->copy();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks