Skip to content

Instantly share code, notes, and snippets.

@gsauthof
Created January 27, 2016 21:59
Show Gist options
  • Save gsauthof/c955f727606f4a5b0cc2 to your computer and use it in GitHub Desktop.
Save gsauthof/c955f727606f4a5b0cc2 to your computer and use it in GitHub Desktop.
Simplified, shortened version of http://unix.stackexchange.com/a/163115/1131, a clipboard dump tool
// source: http://unix.stackexchange.com/a/163115/1131
// GS, 2016-01-27, simplify the code a little bit
#include <QApplication>
#include <QTimer>
#include <QClipboard>
#include <QMimeData>
#include <QDebug>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
static void qtmain()
{
QClipboard *clip = QApplication::clipboard();
for (QString &formatName: clip->mimeData()->formats()) {
string s(formatName.toStdString());
QByteArray arr(clip->mimeData()->data(formatName));
cout << "name=" << s << ", size=" << arr.size() << ' ';
cout << setw(2) << setfill('0') << hex;
for (auto b : arr)
cout << static_cast<unsigned>(static_cast<unsigned char>(b)) << ' ';
cout << setw(0) << dec << '\n';
}
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QTimer::singleShot(0, []() { qtmain(); QApplication::quit(); } );
return app.exec();
}
/* compile via:
g++ -fPIC -Wall -std=c++11 -I/usr/include/qt5{/QtCore,/QtWidgets,/QtGui,} xclipshow.cpp -lQt5{Widgets,Gui,Core}
or:
g++ -Wall -std=c++11 -fPIC xclipshow.cpp -o xclipshow $(pkg-config --cflags --libs Qt5Gui Qt5Core Qt5Widgets)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment