added shortcut to re-read the messages from queue TG-54

This commit is contained in:
JesseQu 2025-08-29 11:18:13 +08:00
parent 4801929f44
commit 511920bd13
2 changed files with 44 additions and 10 deletions

View File

@ -37,7 +37,8 @@ add_compile_definitions(GIT_VERSION="${GIT_VERSION}")
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
find_package(Qt6 COMPONENTS Core Network REQUIRED)
find_package(Qt6 COMPONENTS Core Network Widgets REQUIRED)
find_package(qxtglobalshortcut REQUIRED)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
@ -55,7 +56,7 @@ add_executable(events
main.cpp
)
target_link_libraries(events Qt6::Core Qt6::Network qamqp)
target_link_libraries(events Qt6::Core Qt6::Network Qt6::Widgets qamqp qxtglobalshortcut)
set_target_properties(events PROPERTIES
AUTOMOC ON

View File

@ -1,6 +1,9 @@
#include <QCoreApplication>
#include <QApplication>
#include <QTextStream>
#include <QDebug>
#include <qxtglobalshortcut.h>
#include "qamqpclient.h"
#include "qamqpexchange.h"
#include "qamqpqueue.h"
@ -19,6 +22,10 @@ public Q_SLOTS:
m_client.connectToHost();
}
void OneShot(void) {
m_client.connectToHost();
}
private Q_SLOTS:
void clientConnected() {
QAmqpQueue *queue = m_client.createQueue("hello");
@ -42,13 +49,13 @@ private Q_SLOTS:
queue->get(false);
}
qDebug() << " [*] Waiting for messages. To exit press CTRL+C";
qDebug() << Qt::endl << " [*] Waiting for messages. To exit press CTRL+C";
queue->ack(3, false); // Acknowledgement the 3rd message.
// queue->ack(3, false); // Acknowledgement the 3rd message.
queue->reopen();
// queue->reopen();
// m_client.disconnectFromHost();
m_client.disconnectFromHost();
}
void messageReceived() {
@ -71,10 +78,36 @@ private:
int main(int argc, char **argv)
{
qDebug() << " Recieve starts ... ";
QCoreApplication app(argc, argv);
qDebug() << " " << Qt::endl;
QApplication app(argc, argv);
QTextStream out(stdout);
QTextStream err(stderr);
const QKeySequence shortcut("Ctrl+Shift+Z");
const QxtGlobalShortcut globalShortcut(shortcut);
if ( !globalShortcut.isValid() ) {
err << QString("Error: Failed to set shortcut %1")
.arg(shortcut.toString()) << Qt::endl;
return 1;
}
out << QString("Press shortcut %1 (or CTRL+C to exit)").arg(shortcut.toString()) << Qt::endl;
Receiver receiver;
QObject::connect(
&globalShortcut, &QxtGlobalShortcut::activated, &globalShortcut,
[&]{
// out << QLatin1String("Shortcut pressed!") << Qt::endl;
receiver.OneShot();
// QApplication::quit();
});
receiver.start();
return app.exec();
}