Pop event on block

This commit is contained in:
danielSanchezQ 2026-02-05 14:36:26 +00:00
parent ee5805690c
commit 650d8b218c
2 changed files with 22 additions and 1 deletions

View File

@ -1,7 +1,11 @@
#include "logos_blockchain_module.h"
#include <QtCore/QDebug>
#include <QtCore/QEvent>
#include <QtCore/QCoreApplication>
#include <iostream>
#include <memory>
LogosBlockchainModule::LogosBlockchainModule() = default;
@ -86,7 +90,11 @@ int LogosBlockchainModule::subscribe() {
return 1;
}
subscribe_to_new_blocks(node, [](const char* block) { std::cout << "Received new block: " << block << std::endl; });
subscribe_to_new_blocks(node, [](const char* block) {
std::cout << "Received new block: " << block << std::endl;
auto* event = new BlockEvent(block);
QCoreApplication::postEvent(qApp, event);
});
return 0;
}

View File

@ -2,6 +2,19 @@
#include "i_logos_blockchain_module.h"
class BlockEvent : public QEvent {
public:
static const QEvent::Type BlockEventType = static_cast<QEvent::Type>(QEvent::User + 111);
BlockEvent(const char* blockData) : QEvent(BlockEventType), block(blockData, &free_block) {}
~BlockEvent() = default;
std::shared_ptr<const char> block;
private:
static void free_block(const char* ptr) {
if (ptr) free_cstring(ptr);
}
};
class LogosBlockchainModule final : public QObject, public PluginInterface, public ILogosBlockchainModule {
Q_OBJECT
Q_PLUGIN_METADATA(IID ILogosBlockchainModule_iid FILE LOGOS_BLOCKCHAIN_MODULE_METADATA_FILE)