Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move pubnub_qt into main thread #166

Merged
merged 7 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions qt/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# Pubnub C-core for Qt
# PubNub C-core for Qt

This is a part of C-core for the Qt. It is tested to work only with
Qt5 and Qt6. It builds on Qt4, too, but there are some run-time issues, i.e.
publishing some JSON object fails.
The PubNub Qt SDK is a part of the PubNub C-core SDK. Unlike the C++ wrapper, which wraps a full-featured C-core platform, this is a Qt-native C-core of sorts. It provides its own Qt API, using as many C-core modules as possible.

Unlike the C++ wrapper, which wraps a "full featured" C-core
platform, this is a "Qt-native C-core" of sorts. It provides
it's own (Qt) API, while using as much of C-core modules as
posible.
## Supported Qt versions

There are sample projects:
This SDK works with Qt5 and Qt6. It builds on Qt4, too, but there are some runtime issues, e.g.: publishing a JSON object fails.

- `pubnub.pro`, which will build a Qt command line application which
executes most of the Pubnub transactions/operations - similar to the
`pubnub_sync_sample` or `pubnub_callback_sample` from C-core.
- `pubnub_gui.pro`, which will build a Qt GUI application, a
"minimalistic" Pubnub console
If you have many Qt versions on your machine, use Qt5 or Qt6 (while Qt6 is Unix-tested only). To select the correct version, you can use the `qtchooser` app. For example, run `qtchooser -run-tool=qmake -qt=5 pubnub.pro`. This creates a `Makefile` that uses Qt5 tools.

To build the samples, run `qmake pubnub.pro` or `qmake
pubnub_gui.pro`, and then `make` or, on Windows if using MSVC, `nmake`
or `jom`.
Of course, you may also use the provided Qt projects in Qt Creator.

If you have many Qt versions on your machine, be sure to use
the Qt5 or Qt6 (whereas QT6 is unix tested only) tools, for which purpose you may utilize the `qtchooser`
app. For example, do:
## Sample projects

qtchooser -run-tool=qmake -qt=5 pubnub.pro
We provide the following sample projects for your convenience:

That will create the `Makefile` that will use Qt5 tools.
- `pubnub.pro`, which builds a Qt command line application that executes most of the Pubnub transactions/operations. It's similar to `pubnub_sync_sample` or `pubnub_callback_sample` from the C-core SDK.
- `pubnub_gui.pro`, which builds a Qt GUI application, a minimalistic Pubnub console.

Of course, you may also use the provided Qt projects in Qt Creator.
To build the projects:

1. Run `qmake pubnub.pro` or `qmakepubnub_gui.pro`
2. Run `make` or, if you use MSVC on Windows, `nmake` or `jom`.

## Additional defines

With PubNub Qt SDK, we provided some additional defines that change the behavior of the SDK:

|Flag|Required|Description|
|---|---|---|
|`PUBNUB_QT`|Required|Enables C-core code to fit Qt requirements.|
|`PUBNUB_QT_MOVE_TO_THREAD`|Pptional, enabled by default|Uses the [`moveToThread()`](https://doc.qt.io/qt-6/qobject.html#moveToThread) function to organize SDK timers.|
2 changes: 1 addition & 1 deletion qt/pubnub.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ HEADERS += pubnub_qt.h pubnub_qt_sample.h
SOURCES += pubnub_qt.cpp pubnub_qt_sample.cpp ../core/pubnub_ccore.c ../core/pubnub_ccore_pubsub.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c ../lib/pb_strncasecmp.c ../core/pubnub_memory_block.c ../core/pbcc_set_state.c
win32:SOURCES += ../core/c99/snprintf.c

DEFINES += PUBNUB_QT
DEFINES += PUBNUB_QT PUBNUB_QT_MOVE_TO_THREAD

INCLUDEPATH += ..
win32:INCLUDEPATH += ../core/c99
Expand Down
2 changes: 1 addition & 1 deletion qt/pubnub_gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ HEADERS += pubnub_qt.h pubnub_qt_gui_sample.h
SOURCES += pubnub_qt.cpp pubnub_qt_gui_sample.cpp ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c ../lib/pb_strncasecmp.c ../core/pubnub_memory_block.c ../core/pbcc_set_state.c
win32:SOURCES += ../core/c99/snprintf.c

DEFINES += PUBNUB_QT
DEFINES += PUBNUB_QT PUBNUB_QT_MOVE_TO_THREAD

INCLUDEPATH += ..
win32:INCLUDEPATH += ../core/c99
Expand Down
7 changes: 7 additions & 0 deletions qt/pubnub_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ extern "C" {
}

#include <QtNetwork>
#ifdef PUBNUB_QT_MOVE_TO_THREAD
#include <QApplication>
#endif

/* Minimal acceptable message length difference, between unpacked and packed message, in percents */
#define PUBNUB_MINIMAL_ACCEPTABLE_COMPRESSION_RATIO 10
Expand Down Expand Up @@ -69,6 +72,10 @@ pubnub_qt::pubnub_qt(QString pubkey, QString keysub)
, d_mutex(QMutex::Recursive)
#endif
{
#ifdef PUBNUB_QT_MOVE_TO_THREAD
this->moveToThread(QApplication::instance()->thread());
#endif

pbcc_init(d_context.data(), d_pubkey.data(), d_keysub.data());
connect(&d_qnam,
SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
Expand Down
Loading