automatically copy selected text
-
Hi and welcome to devnet,
There's no need for that, have a look at copyAvailable and copy
-
Hi and welcome to devnet,
There's no need for that, have a look at copyAvailable and copy
-
Sorry, I misunderstood that. What version of Qt 5 are you using ?
-
wrote on 20 Jun 2015, 22:57 last edited by
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. -
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.wrote on 21 Jun 2015, 18:28 last edited by ravas@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... ;-] -
@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... ;-]wrote on 21 Jun 2015, 19:06 last edited byI 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.)"
-
@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... ;-]@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.
-
@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.
-
wrote on 13 Oct 2015, 22:28 last edited by
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.