Performance Issue with QClipboard Class

252 views Asked by At

I have an instance of QClipboard and I want to shift data to it whenever user clicks somewhere in the Application. It seems like there are sometimes performance issues with QClipboard which causes the application to freeze because data gets put on OS clipboard of linux.

QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(QString("Glorious Text"), QClipboard::Clipboard);

It does not happen every time but every fifth or sixth click it freezes for some seconds. So I can not really reproduce properly.

1

There are 1 answers

0
Zaragesh On BEST ANSWER

https://www.medo64.com/2019/12/copy-to-clipboard-in-qt/ solved it for me.

QClipboard* clipboard = QApplication::clipboard();

clipboard->setText(text, QClipboard::Clipboard);

if (clipboard->supportsSelection()) {
    clipboard->setText(text, QClipboard::Selection);
}

#if defined(Q_OS_LINUX)
    QThread::msleep(1); //workaround for copied text not being available...
#endif