QClipboard in Linux



  • 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!


  • Moderators

    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.



  • 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());
        }
    }

  • Moderators

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.