4

I want to copy some string to clipboard in my C++ application. How can I do that? Also is it possible to copy the formatting as well? Thank You

Synxis
  • 9,236
  • 2
  • 42
  • 64
Cool_Coder
  • 4,888
  • 16
  • 57
  • 99

1 Answers1

14

You said you use Qt in one of your comments.

Qt has the class QClipboard, which is what you want (bonus: this is cross-platform).

You can put almost anything you want, data is managed via MIME types. That means you can use your own data formatting in the clipboard, with a 'custom' MIME type. Note that formatting is usually done with html text (text/html), whereas plain text is in text/plain (for plain text Qt provides the function text()).

Synxis
  • 9,236
  • 2
  • 42
  • 64
  • Interesting. When you're saying it's cross-platform, I suppose it still needs to be initialized/configured to a specific platform? – SomeWittyUsername Apr 01 '13 at 11:07
  • 1
    cross-platform because Qt is cross-platform. There still are some corner cases (ex: global mouse on X11), but for the common use it works the same on all supported platforms (which is at least Windows, Linux, Mac, and some phones). There is no manual initialization, all is done by Qt. – Synxis Apr 01 '13 at 11:10
  • I didn't mean it has to be manual and can be set by the QT itself according to environment settings but the underlying implementation surely varies. – SomeWittyUsername Apr 01 '13 at 11:17
  • 1
    Yes, that's true. The user have nothing to initialize, but Qt have some large `#ifdef WIN ... #else ... #endif` parts in its code that do the work ;). – Synxis Apr 01 '13 at 11:19