Solved [solved] experimenting nzmqt hello world example
-
hello
i installed zmq on mac using brew install zmq
followed by downloading nzmqt from git hub, i tried to create a new project with the following content, where i added the pri file given in githubQT -= gui QT += core CONFIG += c++11 console CONFIG -= app_bundle TARGET = nzmqt_app VERSION = 3.2.1 #DESTDIR = $$_PRO_FILE_PWD_/../bin TEMPLATE = app # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp macx: LIBS += -L$$PWD/../../../../../usr/local/Cellar/zeromq/4.3.2/lib/ -lzmq INCLUDEPATH += $$PWD/../../../../../usr/local/Cellar/zeromq/4.3.2/include DEPENDPATH += $$PWD/../../../../../usr/local/Cellar/zeromq/4.3.2/include include(../../Downloads/nzmqt-master/nzmqt.pri) HEADERS +=
I made a simple project with the following content
#include <QCoreApplication> #include "NzmqtApp.hpp" #include <QtDebug> QCoreApplication* b; nzmqt::samples::SampleBase* commandImpl = nullptr ; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); b=&a; return a.exec(); } void run() { nzmqt::ZMQContext* context= nzmqt::createDefaultContext(b); context->start(); QString address = "127.0.0.1"; QString topic = "abc"; commandImpl = new nzmqt::samples::pubsub::Publisher(*context, address, topic,b); }
The project has compile failure due to line
```
commandImpl = new nzmqt::samples::pubsub::Publisher(*context, address, topic,b);
I get symbols not found for archiecture x86_64, linker command failed with exit code 1
Undefined symbols for architecture x86_64:
"vtable for nzmqt::samples::SampleBase", referenced from:
nzmqt::samples::SampleBase::SampleBase(QObject*) in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for nzmqt::samples::pubsub::Publisher", referenced from:
nzmqt::samples::pubsub::Publisher::Publisher(nzmqt::ZMQContext&, QString const&, QString const&, QObject*) in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [nzmqt_app] Error 1
21:55:51: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project testnmqt (kit: Desktop Qt 5.12.1 CLang)
When executing step "Make"
21:55:51: Elapsed time: 00:02.if i comment it out, it compiles fine. I am still new to nzmqt and still dont know how to use it. any help is appreciated.
-
I corrected the code in the main.cpp to the following, now it compiles, but when i run a second instance as a subscriber, it does not receive this publisher ..
what is missing?#include <QCoreApplication> #include <nzmqt/nzmqt.hpp> #include <QtDebug> #include <nzmqt/SampleBase.hpp> #include <nzmqt/Subscriber.hpp> #include <nzmqt/Publisher.hpp> QCoreApplication* b; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); b=&a; nzmqt::samples::SampleBase* commandImpl = nullptr ; nzmqt::ZMQContext* context= nzmqt::createDefaultContext(b); context->start(); QString address = "tcp://127.0.0.1:1234"; QString topic = "ping"; commandImpl = new nzmqt::samples::pubsub::Publisher(*context, address, topic,b); return a.exec(); } void run() { }
-
this should work now
```
commandImpl->start();