added shortcut to re-read the messages from queue TG-54
This commit is contained in:
parent
4801929f44
commit
511920bd13
|
|
@ -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
|
||||
|
|
|
|||
49
main.cpp
49
main.cpp
|
|
@ -1,6 +1,9 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QApplication>
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
|
||||
#include <qxtglobalshortcut.h>
|
||||
|
||||
#include "qamqpclient.h"
|
||||
#include "qamqpexchange.h"
|
||||
#include "qamqpqueue.h"
|
||||
|
|
@ -10,7 +13,7 @@ class Receiver : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
Receiver(QObject *parent = 0) : QObject(parent) {
|
||||
m_client.setAutoReconnect(true);
|
||||
m_client.setAutoReconnect(true);
|
||||
}
|
||||
|
||||
public Q_SLOTS:
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue