This code is invalid - as the type identification is done at runtime, the compiler can't decide what function to call when building the code. The correct code is:
QLineEdit *le
= qobject_cast<QLineEdit
*>
(activeWidget
);
if(le) le->paste();
else {
QPlainTextEdit *pte = qobject_cast<QPlainTextEdit*>(activeWidget);
if(pte) pte->paste();
else qFatal("Unknown widget found");
}
QLineEdit *le = qobject_cast<QLineEdit*>(activeWidget);
if(le) le->paste();
else {
QPlainTextEdit *pte = qobject_cast<QPlainTextEdit*>(activeWidget);
if(pte) pte->paste();
else qFatal("Unknown widget found");
}
To copy to clipboard, switch view to plain text mode
Or a simple and brilliant abuse of one of Qt's features:
QMetaObject::invokeMethod(activeWidget, "paste");
To copy to clipboard, switch view to plain text mode
which makes use of a fact that paste() is a slot in both classes.
Bookmarks