automatically copy selected text
-
Sorry, I misunderstood that. What version of Qt 5 are you using ?
-
When I double click on a word it will copy the whole word.
When I start on the right of the word and drag to select,
it will copy the right most character;
starting on the left it will copy the left most character. -
Hi @ravas ,
Use the
selectionChanged()
signal instead.The
copyAvailable()
signal is only emitted when you change from available to not-available (or the other way round). It is not emitted when you add more characters to your selection. -
@JKSH I get an error with:
void Notepad::on_textEdit_selectionChanged() { ui->textEdit->copy(); }
"OleSetClipboard: Failed to set mime data (text/plain, text/html, application/vnd.oasis.opendocument.text) on clipboard: COM error 0x800401d0 (Unknown error 0x0ffffffff800401d0) (The parameter is incorrect.)"
I tried another way:
void Notepad::on_textEdit_selectionChanged() { QTextCursor cursor(ui->textEdit->textCursor()); const QString sel = cursor.selectedText(); QClipboard *myClip = qApp->clipboard(); myClip->setText(sel); }
This gives the error "invalid use of incomplete type class QClipboard"...
I'm not sure how to complete it... ;-] -
I forgot #include <QClipboard>
However there is still an error...
"OleSetClipboard: Failed to set mime data (text/plain) on clipboard: COM error 0x800401d0 (Unknown error 0x0ffffffff800401d0) (The parameter is incorrect.)"
-
@ravas said:
void Notepad::on_textEdit_selectionChanged() { ui->textEdit->copy(); }
This code is correct.
I tested your code, and it works for me. I used Qt 5.4.1, both MinGW 4.9.1 and MSVC 2013. My OS is Windows 8.1 Pro x64.
"OleSetClipboard: Failed to set mime data (text/plain, text/html, application/vnd.oasis.opendocument.text) on clipboard: COM error 0x800401d0 (Unknown error 0x0ffffffff800401d0) (The parameter is incorrect.)"
This is an error with your Windows clipboard, not with Qt. Make sure that other programs are not trying to use the clipboard at the same time. Try rebooting your computer and see if that helps.
-
I got the Clipboard error when I had RealVncViewer running at the same time. I closed VNC & then the application ran without the clipboard error.