Reputation: 64276
In Linux after text selecting it copies to buffer, so than we could paste it by clicking middle button of the mouse. I think that there is a special buffer for this thing. I want to use it. How could i get data of selected text?
Thanks.
Upvotes: 3
Views: 3514
Reputation: 8886
You need to distinguish between selection and clipboard. The QClipboard
documentation has this in the Notes for X11 Users section:
The X11 Window System has the concept of a separate selection and clipboard. When text is selected, it is immediately available as the global mouse selection. The global mouse selection may later be copied to the clipboard. By convention, the middle mouse button is used to paste the global mouse selection.
With QClipboard::Mode
you can select which type (clipboard or selection) you want to access. The important part is that you need to be aware about the difference between selection and clipboard.
Upvotes: 3
Reputation: 25522
the system that actually handles the selection and pasting system is X11 Windows. When you e.g paint some text in your favorite editor, the application sends and X11 request which tells to the X11 server that you have an active selection. If you then click the middle mouse button somewhere, the X11 server queries the application which told the server about the selection for the actual contents. Then the contents are forwarded to the receiving application.
Libraries like Qt provide wrappers for this mechanism, but the underlying mechanism is X11.
Upvotes: 1
Reputation: 20881
Just a more accurate answer than Paul Dixon's that answers your needs:
QClipboard* clipboard = QApplication::clipboard();
QString selectedText = clipboard->text(QClipboard::Selection);
Upvotes: 7
Reputation: 300855
If you're using Qt, have you read the fine manual page on QClipboard?
QClipboard *clipboard = QApplication::clipboard();
QString clipboardText = clipboard->text();
Upvotes: 1