Results 1 to 3 of 3

Thread: QClipboard setText not working

  1. #1
    Join Date
    May 2014
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default QClipboard setText not working

    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!

    Qt Code:
    1. auto *pClip=QApplication::clipboard();
    2. pClip->clear();//no effect?
    3. pClip->setText("abc");//no effect?
    4. QString str=pClip->text()//returns whatever was in clipboard prior to above code
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2012
    Location
    Poland/UK
    Posts
    28
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QClipboard setText not working

    Try this code

    Add and show
    Qt Code:
    1. QString textToClipboard = "I'm in clipboard ! :)";
    2. QClipboard *clipboard = QApplication::clipboard();
    3. clipboard->clear();
    4. clipboard->setText(textToClipboard);
    5.  
    6. QString clipboardText = clipboard->text();
    7. if(clipboardText.isEmpty())
    8. {
    9. qDebug() << "Clipboard is empty!";
    10. }
    11. else
    12. {
    13. qDebug() << "Clipboard is not empty: " << clipboardText;
    14. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2014
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QClipboard setText not working

    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!

Similar Threads

  1. QClipboard
    By Qiieha in forum Qt Programming
    Replies: 4
    Last Post: 19th December 2012, 11:05
  2. Replies: 4
    Last Post: 1st December 2011, 20:53
  3. QLabel->setText() sometimes not working
    By cass in forum Newbie
    Replies: 8
    Last Post: 16th May 2010, 14:12
  4. QPushButton - setText with "\n" not working
    By gboelter in forum Newbie
    Replies: 7
    Last Post: 10th February 2008, 04:27
  5. setText not working
    By MarkoSan in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 14:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.