Skip to content

Instantly share code, notes, and snippets.

@nocnokneo
Forked from gsauthof/xclipshow.cpp
Last active October 8, 2020 15:19
Show Gist options
  • Save nocnokneo/ed3797c3af061c7699df00f7b26b08b1 to your computer and use it in GitHub Desktop.
Save nocnokneo/ed3797c3af061c7699df00f7b26b08b1 to your computer and use it in GitHub Desktop.
Simplified, shortened version of http://unix.stackexchange.com/a/163115/1131, a clipboard dump tool
cmake_minimum_required(VERSION 3.0.0)
project(xclipshow)
find_package(Qt5Widgets)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_definitions(-std=c++11)
add_executable(xclipshow
xclipshow.cpp
)
qt5_use_modules(xclipshow Widgets Core)
// 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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment