Skip to content

Commit cfe7dcc

Browse files
authored
feat: using Qt with 3rd Party Signals and Slots (#17067)
Replace signals,slots and emit with Q_SIGNALS,Q_SLOTS and Q_EMIT Because these names will be used by a 3rd party library
1 parent e3c0a3e commit cfe7dcc

37 files changed

+271
-271
lines changed

modules/openapi-generator/src/main/resources/cpp-qt-client/HttpRequest.cpp.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void {{prefix}}HttpRequestWorker::on_reply_finished(QNetworkReply *reply) {
409409
}
410410
process_response(reply);
411411
reply->deleteLater();
412-
emit on_execution_finished(this);
412+
Q_EMIT on_execution_finished(this);
413413
}
414414

415415
void {{prefix}}HttpRequestWorker::on_reply_timeout(QNetworkReply *reply) {
@@ -419,7 +419,7 @@ void {{prefix}}HttpRequestWorker::on_reply_timeout(QNetworkReply *reply) {
419419
disconnect(reply, nullptr, nullptr, nullptr);
420420
reply->abort();
421421
reply->deleteLater();
422-
emit on_execution_finished(this);
422+
Q_EMIT on_execution_finished(this);
423423
}
424424

425425
void {{prefix}}HttpRequestWorker::process_response(QNetworkReply *reply) {

modules/openapi-generator/src/main/resources/cpp-qt-client/HttpRequest.h.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public:
7272
void setRequestCompressionEnabled(bool enable);
7373
int getHttpResponseCode() const;
7474

75-
signals:
75+
Q_SIGNALS:
7676
void on_execution_finished({{prefix}}HttpRequestWorker *worker);
7777

7878
private:

modules/openapi-generator/src/main/resources/cpp-qt-client/README.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Example : public QObject {
4242
{{#allParams}}
4343
{{{dataType}}} create();
4444
{{/allParams}}
45-
public slots:
45+
public Q_SLOTS:
4646
void exampleFunction1();
4747
};
4848
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}

modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void {{classname}}::enableResponseCompression() {
163163
}
164164

165165
void {{classname}}::abortRequests() {
166-
emit abortRequestsSignal();
166+
Q_EMIT abortRequestsSignal();
167167
}
168168

169169
QString {{classname}}::getParamStylePrefix(const QString &style) {
@@ -676,7 +676,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
676676
connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater);
677677
connect(worker, &QObject::destroyed, this, [this]() {
678678
if (findChildren<{{prefix}}HttpRequestWorker*>().count() == 0) {
679-
emit allPendingRequestsCompleted();
679+
Q_EMIT allPendingRequestsCompleted();
680680
}
681681
});{{#authMethods}}{{#isOAuth}}{{#isCode}}
682682
_OauthMethod = 2;
@@ -702,7 +702,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
702702
connect(this, &{{classname}}::abortRequestsSignal, _latestWorker, &QObject::deleteLater);
703703
connect(_latestWorker, &QObject::destroyed, [this](){
704704
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
705-
emit allPendingRequestsCompleted();
705+
Q_EMIT allPendingRequestsCompleted();
706706
}
707707
});
708708

@@ -732,7 +732,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
732732
connect(this, &{{classname}}::abortRequestsSignal, _latestWorker, &QObject::deleteLater);
733733
connect(_latestWorker, &QObject::destroyed, [this](){
734734
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
735-
emit allPendingRequestsCompleted();
735+
Q_EMIT allPendingRequestsCompleted();
736736
}
737737
});
738738

@@ -762,7 +762,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
762762
connect(this, &{{classname}}::abortRequestsSignal, _latestWorker, &QObject::deleteLater);
763763
connect(_latestWorker, &QObject::destroyed, [this](){
764764
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
765-
emit allPendingRequestsCompleted();
765+
Q_EMIT allPendingRequestsCompleted();
766766
}
767767
});
768768

@@ -792,7 +792,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
792792
connect(this, &{{classname}}::abortRequestsSignal, _latestWorker, &QObject::deleteLater);
793793
connect(_latestWorker, &QObject::destroyed, [this](){
794794
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
795-
emit allPendingRequestsCompleted();
795+
Q_EMIT allPendingRequestsCompleted();
796796
}
797797
});
798798

@@ -857,8 +857,8 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
857857
worker->deleteLater();
858858

859859
if (worker->error_type == QNetworkReply::NoError) {
860-
emit {{nickname}}Signal({{#returnType}}output{{/returnType}});
861-
emit {{nickname}}SignalFull(worker{{#returnType}}, output{{/returnType}});{{#authMethods}}{{#isOAuth}}{{#isCode}}
860+
Q_EMIT {{nickname}}Signal({{#returnType}}output{{/returnType}});
861+
Q_EMIT {{nickname}}SignalFull(worker{{#returnType}}, output{{/returnType}});{{#authMethods}}{{#isOAuth}}{{#isCode}}
862862
} else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){
863863
connect(&_authFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable()));
864864
QStringList scope;
@@ -870,7 +870,7 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
870870
QString tokenUrl("{{tokenUrl}}");
871871
//TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like
872872
_authFlow.setVariables(authorizationUrl, tokenUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId", "clientSecret");
873-
emit _authFlow.authenticationNeeded();{{/isCode}}
873+
Q_EMIT _authFlow.authenticationNeeded();{{/isCode}}
874874
{{#isImplicit}}
875875
} else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){
876876
connect(&_implicitFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable()));
@@ -882,7 +882,7 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
882882
QString authorizationUrl("{{authorizationUrl}}");
883883
//TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like
884884
_implicitFlow.setVariables(authorizationUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId");
885-
emit _implicitFlow.authenticationNeeded();{{/isImplicit}}
885+
Q_EMIT _implicitFlow.authenticationNeeded();{{/isImplicit}}
886886
{{#isApplication}}
887887
} else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){
888888
connect(&_credentialFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable()));
@@ -894,7 +894,7 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
894894
QString tokenUrl("{{tokenUrl}}");
895895
//TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like
896896
_credentialFlow.setVariables(tokenUrl , scopeStr, "clientId", "clientSecret");
897-
emit _credentialFlow.authenticationNeeded();{{/isApplication}}
897+
Q_EMIT _credentialFlow.authenticationNeeded();{{/isApplication}}
898898
{{#isPassword}}
899899
} else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){
900900
connect(&_passwordFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable()));
@@ -906,7 +906,7 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
906906
QString tokenUrl("{{tokenUrl}}");
907907
//TODO get clientID and Secret and state in the config? https://swagger.io/docs/specification/authentication/oauth2/ states that you should do as you like
908908
_passwordFlow.setVariables(tokenUrl , scopeStr ,"clientId", "clientSecret", "username", "password");
909-
emit _passwordFlow.authenticationNeeded();
909+
Q_EMIT _passwordFlow.authenticationNeeded();
910910
{{/isPassword}}{{/isOAuth}}{{/authMethods}}
911911
} else {
912912
@@ -924,8 +924,8 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
924924
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
925925
#endif
926926
927-
emit {{nickname}}SignalE({{#returnType}}output, {{/returnType}}error_type, error_str);
928-
emit {{nickname}}SignalEFull(worker, error_type, error_str);
927+
Q_EMIT {{nickname}}SignalE({{#returnType}}output, {{/returnType}}error_type, error_str);
928+
Q_EMIT {{nickname}}SignalEFull(worker, error_type, error_str);
929929

930930
#if defined(_MSC_VER)
931931
#pragma warning(pop)
@@ -935,8 +935,8 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
935935
#pragma GCC diagnostic pop
936936
#endif
937937

938-
emit {{nickname}}SignalError({{#returnType}}output, {{/returnType}}error_type, error_str);
939-
emit {{nickname}}SignalErrorFull(worker, error_type, error_str);
938+
Q_EMIT {{nickname}}SignalError({{#returnType}}output, {{/returnType}}error_type, error_str);
939+
Q_EMIT {{nickname}}SignalErrorFull(worker, error_type, error_str);
940940
}
941941
}
942942

modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private:
8585
{{#operations}}{{#operation}}
8686
void {{nickname}}Callback({{prefix}}HttpRequestWorker *worker);{{/operation}}{{/operations}}
8787

88-
signals:
88+
Q_SIGNALS:
8989
{{#operations}}{{#operation}}
9090
void {{nickname}}Signal({{#returnType}}{{{.}}} summary{{/returnType}});{{/operation}}{{/operations}}
9191
{{#operations}}{{#operation}}
@@ -102,7 +102,7 @@ signals:
102102
void abortRequestsSignal();
103103
void allPendingRequestsCompleted();
104104

105-
public slots:
105+
public Q_SLOTS:
106106
void tokenAvailable();
107107
};
108108

modules/openapi-generator/src/main/resources/cpp-qt-client/oauth.cpp.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ oauthToken OauthBase::getToken(QString scope)
3131
void OauthBase::addToken(oauthToken token)
3232
{
3333
m_oauthTokenMap.insert(token.getScope(),token);
34-
emit tokenReceived();
34+
Q_EMIT tokenReceived();
3535
3636
}
3737

@@ -341,7 +341,7 @@ void ReplyServer::read()
341341
}
342342
socket->close();
343343
344-
emit dataReceived(queryParams);
344+
Q_EMIT dataReceived(queryParams);
345345
}
346346
347347
{{#cppNamespaceDeclarations}}

modules/openapi-generator/src/main/resources/cpp-qt-client/oauth.h.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public:
5858
private:
5959
QByteArray m_reply;
6060

61-
signals:
61+
Q_SIGNALS:
6262
void dataReceived(QMap<QString, QString>);
6363

64-
public slots:
64+
public Q_SLOTS:
6565
void onConnected();
6666
void read();
6767
void start();
@@ -88,11 +88,11 @@ protected:
8888
QString m_scope, m_accessType, m_state, m_redirectUri, m_clientId, m_clientSecret;
8989
bool m_linked;
9090

91-
public slots:
91+
public Q_SLOTS:
9292
virtual void authenticationNeededCallback()=0;
9393
void onFinish(QNetworkReply *rep);
9494

95-
signals:
95+
Q_SIGNALS:
9696
void authenticationNeeded();
9797
void tokenReceived();
9898
};
@@ -110,7 +110,7 @@ public:
110110
private:
111111
ReplyServer m_server;
112112
113-
public slots:
113+
public Q_SLOTS:
114114
void authenticationNeededCallback() override;
115115
void onVerificationReceived(const QMap<QString, QString> response);
116116
@@ -129,7 +129,7 @@ public:
129129
private:
130130
ReplyServer m_server;
131131
132-
public slots:
132+
public Q_SLOTS:
133133
void authenticationNeededCallback() override;
134134
void ImplicitTokenReceived(const QMap<QString, QString> response);
135135
};
@@ -144,7 +144,7 @@ public:
144144
void unlink() override;
145145
void setVariables(QString tokenUrl, QString scope, QString clientId, QString clientSecret);
146146
147-
public slots:
147+
public Q_SLOTS:
148148
void authenticationNeededCallback() override;
149149
150150
};
@@ -162,7 +162,7 @@ public:
162162
private:
163163
QString m_username, m_password;
164164
165-
public slots:
165+
public Q_SLOTS:
166166
void authenticationNeededCallback() override;
167167
168168
};

modules/openapi-generator/src/main/resources/cpp-qt-qhttpengine-server/apihandler.h.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public:
2020
virtual ~{{classname}}Handler();
2121

2222

23-
public slots:
23+
public Q_SLOTS:
2424
{{#operations}}{{#operation}}virtual void {{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
2525
{{/operation}}{{/operations}}
2626

modules/openapi-generator/src/main/resources/cpp-qt-qhttpengine-server/apirequest.cpp.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void {{classname}}Request::{{nickname}}Request({{#hasPathParams}}{{#pathParams}}
108108
{{/isArray}}
109109
{{/bodyParam}}{{/bodyParams}}
110110

111-
emit {{nickname}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
111+
Q_EMIT {{nickname}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
112112
}
113113

114114
{{/operation}}{{/operations}}

modules/openapi-generator/src/main/resources/cpp-qt-qhttpengine-server/apirequest.h.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public:
4444

4545
void setResponseHeaders(const QMultiMap<QString,QString>& headers);
4646

47-
signals:
47+
Q_SIGNALS:
4848
{{#operations}}{{#operation}}void {{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
4949
{{/operation}}{{/operations}}
5050

0 commit comments

Comments
 (0)