tags:

views:

353

answers:

4

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?

  • OS: Linux
  • Programming language: c++
  • Own libraries: Qt

Thanks.

+1  A: 

If you're using Qt, have you read the fine manual page on QClipboard?

QClipboard *clipboard = QApplication::clipboard();
QString clipboardText = clipboard->text();
Paul Dixon
It gets data from usual clipboard. It's not that i need.
Ockonal
You might need to expand on your question to indicate the problem you are trying to solve
Paul Dixon
+5  A: 

Just a more accurate answer than Paul Dixon's that answers your needs:

QClipboard* clipboard = QApplication::clipboard();
QString selectedText = clipboard->text(QClipboard::Selection);
Idan K
+1  A: 

Hi,

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.

antti.huima
+2  A: 

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.

bluebrother