Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QClipboard in Linux

QClipboard in Linux

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M Wong
    wrote on last edited by
    #1

    I have been porting my Qt Windows file manger to Linux. One of the problems I have is about QClipboard:

    First some simplified codes:

    Win::Win(QWidget* p) : QWidget(p)
    {
    \\ ...
    connect(qApp->clipboard(), &QClipboard::dataChanged, this, &Win::onCb);
    }
    
    void Win::onCb()
    {
         qDebug() << "QClipboard signal recieved.";
    }
    

    The problem is:

    Cutting / Copying file(s) in Thunar (xfce file manager) or on the desktop, it's OK, QClipboard emits dataChanged() signal.

    But after pasting file in Thunar/Desktop, QClipboard won't emit the dataChanged() signal!

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, welcome to devnet.

      I'm not that familiar with Linux, but AFAIK pasting does not remove/modify content of the clipboard i.e. you can copy once and paste any number of times. Since the contents of the clipboard don't change no signal is emitted.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        M Wong
        wrote on last edited by
        #3

        But a file Cutting and Pasting pair operation moves the files. ie, the source is removed, no more data in the clipboard, the clipboard should emit dataChanged() so that one can update the UI (for example, disable the paste button).

        void Win::onClipboardChanged()
        {
            if (qApp->clipboard()->mimeData()) {
                const QMimeData* pD = qApp->clipboard()->mimeData();
                m_pPasteButton->setEnabled(pD->hasUrls() && pD->Urls().at(0).isLocalFile());
            }
        }
        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Clipboard and physical data storage are two completely different and separate things. The fact that a file moved on a disk has nothing to do with contents of a clipboard. You can cut once and paste multiple times. The information is not removed from the clipboard when you paste.

          dataChanged notifies about clipboard contents change, not changes in filesystem or any other kind. Pasting does not change contents of a clipboard so that is that. It's not a Qt specific behavior. That's just how clipboard works.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved