Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux and clipboard

Tags:

c++

clipboard

qt

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.

like image 631
Max Frai Avatar asked Apr 09 '26 09:04

Max Frai


2 Answers

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

QClipboard* clipboard = QApplication::clipboard();
QString selectedText = clipboard->text(QClipboard::Selection);
like image 75
Idan K Avatar answered Apr 10 '26 23:04

Idan K


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.

like image 28
bluebrother Avatar answered Apr 10 '26 21:04

bluebrother



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!