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 4 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
12 changes: 12 additions & 0 deletions qt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ app. For example, do:
That will create the `Makefile` that will use Qt5 tools.

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

## Additional defines

With PubNub QT SDK we provided some additional defines that changes the behaviour of the SDK
techwritermat marked this conversation as resolved.
Show resolved Hide resolved
depending if they're enabled or not:

|Flag|Status|Description|
|---|---|---|
|`PUBNUB_QT`|required|Enables and disables some C-core code to fit QT requirements|
|`PUBNUB_QT_MOVE_TO_THREAD`|optional, enabled by default|Uses [`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