PDA

View Full Version : QClipboard setText not working



ChiBriTri
29th July 2014, 17:10
I can’t seem to figure out how to get QClipboard to work right. clear and setText seem to do nothing. Am I missing something here? win7 with qt 5.3.1. Thanks in advance!


auto *pClip=QApplication::clipboard();
pClip->clear();//no effect?
pClip->setText("abc");//no effect?
QString str=pClip->text()//returns whatever was in clipboard prior to above code

Coder5546
1st August 2014, 21:53
Try this code

Add and show



QString textToClipboard = "I'm in clipboard ! :)";
QClipboard *clipboard = QApplication::clipboard();
clipboard->clear();
clipboard->setText(textToClipboard);

QString clipboardText = clipboard->text();
if(clipboardText.isEmpty())
{
qDebug() << "Clipboard is empty!";
}
else
{
qDebug() << "Clipboard is not empty: " << clipboardText;
}

ChiBriTri
6th August 2014, 20:24
Just saw this response - thanks!

Unfortunately this produced the same results as my code. However the qdebug code made me look at the output window which outputted a different error that led me to search and see on windows qclipboard must be called from the main thread. It's working now - thanks again!