Skip to content

Commit

Permalink
feat: using Qt with 3rd Party Signals and Slots (#17067)
Browse files Browse the repository at this point in the history
Replace signals,slots and emit with Q_SIGNALS,Q_SLOTS and Q_EMIT

Because these names will be used by a 3rd party library
  • Loading branch information
myml committed Jan 10, 2024
1 parent e3c0a3e commit cfe7dcc
Show file tree
Hide file tree
Showing 37 changed files with 271 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ void {{prefix}}HttpRequestWorker::on_reply_finished(QNetworkReply *reply) {
}
process_response(reply);
reply->deleteLater();
emit on_execution_finished(this);
Q_EMIT on_execution_finished(this);
}

void {{prefix}}HttpRequestWorker::on_reply_timeout(QNetworkReply *reply) {
Expand All @@ -419,7 +419,7 @@ void {{prefix}}HttpRequestWorker::on_reply_timeout(QNetworkReply *reply) {
disconnect(reply, nullptr, nullptr, nullptr);
reply->abort();
reply->deleteLater();
emit on_execution_finished(this);
Q_EMIT on_execution_finished(this);
}

void {{prefix}}HttpRequestWorker::process_response(QNetworkReply *reply) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public:
void setRequestCompressionEnabled(bool enable);
int getHttpResponseCode() const;

signals:
Q_SIGNALS:
void on_execution_finished({{prefix}}HttpRequestWorker *worker);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Example : public QObject {
{{#allParams}}
{{{dataType}}} create();
{{/allParams}}
public slots:
public Q_SLOTS:
void exampleFunction1();
};
{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void {{classname}}::enableResponseCompression() {
}

void {{classname}}::abortRequests() {
emit abortRequestsSignal();
Q_EMIT abortRequestsSignal();
}

QString {{classname}}::getParamStylePrefix(const QString &style) {
Expand Down Expand Up @@ -676,7 +676,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, this, [this]() {
if (findChildren<{{prefix}}HttpRequestWorker*>().count() == 0) {
emit allPendingRequestsCompleted();
Q_EMIT allPendingRequestsCompleted();
}
});{{#authMethods}}{{#isOAuth}}{{#isCode}}
_OauthMethod = 2;
Expand All @@ -702,7 +702,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
connect(this, &{{classname}}::abortRequestsSignal, _latestWorker, &QObject::deleteLater);
connect(_latestWorker, &QObject::destroyed, [this](){
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
Q_EMIT allPendingRequestsCompleted();
}
});

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

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

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

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

if (worker->error_type == QNetworkReply::NoError) {
emit {{nickname}}Signal({{#returnType}}output{{/returnType}});
emit {{nickname}}SignalFull(worker{{#returnType}}, output{{/returnType}});{{#authMethods}}{{#isOAuth}}{{#isCode}}
Q_EMIT {{nickname}}Signal({{#returnType}}output{{/returnType}});
Q_EMIT {{nickname}}SignalFull(worker{{#returnType}}, output{{/returnType}});{{#authMethods}}{{#isOAuth}}{{#isCode}}
} else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){
connect(&_authFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable()));
QStringList scope;
Expand All @@ -870,7 +870,7 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
QString tokenUrl("{{tokenUrl}}");
//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
_authFlow.setVariables(authorizationUrl, tokenUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId", "clientSecret");
emit _authFlow.authenticationNeeded();{{/isCode}}
Q_EMIT _authFlow.authenticationNeeded();{{/isCode}}
{{#isImplicit}}
} else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){
connect(&_implicitFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable()));
Expand All @@ -882,7 +882,7 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
QString authorizationUrl("{{authorizationUrl}}");
//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
_implicitFlow.setVariables(authorizationUrl, scopeStr, "state" , "http://127.0.0.1:9999", "clientId");
emit _implicitFlow.authenticationNeeded();{{/isImplicit}}
Q_EMIT _implicitFlow.authenticationNeeded();{{/isImplicit}}
{{#isApplication}}
} else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){
connect(&_credentialFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable()));
Expand All @@ -894,7 +894,7 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
QString tokenUrl("{{tokenUrl}}");
//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
_credentialFlow.setVariables(tokenUrl , scopeStr, "clientId", "clientSecret");
emit _credentialFlow.authenticationNeeded();{{/isApplication}}
Q_EMIT _credentialFlow.authenticationNeeded();{{/isApplication}}
{{#isPassword}}
} else if(worker->error_type == QNetworkReply::AuthenticationRequiredError){
connect(&_passwordFlow, SIGNAL(tokenReceived()), this, SLOT(tokenAvailable()));
Expand All @@ -906,7 +906,7 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
QString tokenUrl("{{tokenUrl}}");
//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
_passwordFlow.setVariables(tokenUrl , scopeStr ,"clientId", "clientSecret", "username", "password");
emit _passwordFlow.authenticationNeeded();
Q_EMIT _passwordFlow.authenticationNeeded();
{{/isPassword}}{{/isOAuth}}{{/authMethods}}
} else {
Expand All @@ -924,8 +924,8 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
emit {{nickname}}SignalE({{#returnType}}output, {{/returnType}}error_type, error_str);
emit {{nickname}}SignalEFull(worker, error_type, error_str);
Q_EMIT {{nickname}}SignalE({{#returnType}}output, {{/returnType}}error_type, error_str);
Q_EMIT {{nickname}}SignalEFull(worker, error_type, error_str);

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

emit {{nickname}}SignalError({{#returnType}}output, {{/returnType}}error_type, error_str);
emit {{nickname}}SignalErrorFull(worker, error_type, error_str);
Q_EMIT {{nickname}}SignalError({{#returnType}}output, {{/returnType}}error_type, error_str);
Q_EMIT {{nickname}}SignalErrorFull(worker, error_type, error_str);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private:
{{#operations}}{{#operation}}
void {{nickname}}Callback({{prefix}}HttpRequestWorker *worker);{{/operation}}{{/operations}}

signals:
Q_SIGNALS:
{{#operations}}{{#operation}}
void {{nickname}}Signal({{#returnType}}{{{.}}} summary{{/returnType}});{{/operation}}{{/operations}}
{{#operations}}{{#operation}}
Expand All @@ -102,7 +102,7 @@ signals:
void abortRequestsSignal();
void allPendingRequestsCompleted();

public slots:
public Q_SLOTS:
void tokenAvailable();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ oauthToken OauthBase::getToken(QString scope)
void OauthBase::addToken(oauthToken token)
{
m_oauthTokenMap.insert(token.getScope(),token);
emit tokenReceived();
Q_EMIT tokenReceived();
}

Expand Down Expand Up @@ -341,7 +341,7 @@ void ReplyServer::read()
}
socket->close();
emit dataReceived(queryParams);
Q_EMIT dataReceived(queryParams);
}
{{#cppNamespaceDeclarations}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public:
private:
QByteArray m_reply;

signals:
Q_SIGNALS:
void dataReceived(QMap<QString, QString>);

public slots:
public Q_SLOTS:
void onConnected();
void read();
void start();
Expand All @@ -88,11 +88,11 @@ protected:
QString m_scope, m_accessType, m_state, m_redirectUri, m_clientId, m_clientSecret;
bool m_linked;

public slots:
public Q_SLOTS:
virtual void authenticationNeededCallback()=0;
void onFinish(QNetworkReply *rep);

signals:
Q_SIGNALS:
void authenticationNeeded();
void tokenReceived();
};
Expand All @@ -110,7 +110,7 @@ public:
private:
ReplyServer m_server;
public slots:
public Q_SLOTS:
void authenticationNeededCallback() override;
void onVerificationReceived(const QMap<QString, QString> response);
Expand All @@ -129,7 +129,7 @@ public:
private:
ReplyServer m_server;
public slots:
public Q_SLOTS:
void authenticationNeededCallback() override;
void ImplicitTokenReceived(const QMap<QString, QString> response);
};
Expand All @@ -144,7 +144,7 @@ public:
void unlink() override;
void setVariables(QString tokenUrl, QString scope, QString clientId, QString clientSecret);
public slots:
public Q_SLOTS:
void authenticationNeededCallback() override;
};
Expand All @@ -162,7 +162,7 @@ public:
private:
QString m_username, m_password;
public slots:
public Q_SLOTS:
void authenticationNeededCallback() override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public:
virtual ~{{classname}}Handler();


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void {{classname}}Request::{{nickname}}Request({{#hasPathParams}}{{#pathParams}}
{{/isArray}}
{{/bodyParam}}{{/bodyParams}}

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

{{/operation}}{{/operations}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public:

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace {{this}} {
class {{prefix}}ApiRequestHandler : public QHttpEngine::QObjectHandler
{
Q_OBJECT
signals:
Q_SIGNALS:
void requestReceived(QHttpEngine::Socket *socket);
protected:
Expand All @@ -34,10 +34,10 @@ protected:
// If the slot requires all data to be received, check to see if this is
// already the case, otherwise, wait until the rest of it arrives
if (socket->bytesAvailable() >= socket->contentLength()) {
emit requestReceived(socket);
Q_EMIT requestReceived(socket);
} else {
connect(socket, &QHttpEngine::Socket::readChannelFinished, [this, socket]() {
emit requestReceived(socket);
Q_EMIT requestReceived(socket);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt/PetStore/PetApiTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PetApiTests : public QObject {

PFXPet createRandomPet();

private slots:
private Q_SLOTS:
void findPetsByStatusTest();
void createAndGetPetTest();
void updatePetTest();
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt/PetStore/StoreApiTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace test_namespace;
class StoreApiTests : public QObject {
Q_OBJECT

private slots:
private Q_SLOTS:
void placeOrderTest();
void getOrderByIdTest();
void getInventoryTest();
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt/PetStore/UserApiTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UserApiTests : public QObject {

PFXUser createRandomUser();

private slots:
private Q_SLOTS:
void createUserTest();
void createUsersWithArrayInputTest();
void createUsersWithListInputTest();
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using namespace test_namespace;
class Example : public QObject {
Q_OBJECT
PFXPet create();
public slots:
public Q_SLOTS:
void exampleFunction1();
};

Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-qt/client/PFXHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void PFXHttpRequestWorker::on_reply_finished(QNetworkReply *reply) {
}
process_response(reply);
reply->deleteLater();
emit on_execution_finished(this);
Q_EMIT on_execution_finished(this);
}

void PFXHttpRequestWorker::on_reply_timeout(QNetworkReply *reply) {
Expand All @@ -426,7 +426,7 @@ void PFXHttpRequestWorker::on_reply_timeout(QNetworkReply *reply) {
disconnect(reply, nullptr, nullptr, nullptr);
reply->abort();
reply->deleteLater();
emit on_execution_finished(this);
Q_EMIT on_execution_finished(this);
}

void PFXHttpRequestWorker::process_response(QNetworkReply *reply) {
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt/client/PFXHttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PFXHttpRequestWorker : public QObject {
void setRequestCompressionEnabled(bool enable);
int getHttpResponseCode() const;

signals:
Q_SIGNALS:
void on_execution_finished(PFXHttpRequestWorker *worker);

private:
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-qt/client/PFXOauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ oauthToken OauthBase::getToken(QString scope)
void OauthBase::addToken(oauthToken token)
{
m_oauthTokenMap.insert(token.getScope(),token);
emit tokenReceived();
Q_EMIT tokenReceived();

}

Expand Down Expand Up @@ -339,7 +339,7 @@ void ReplyServer::read()
}
socket->close();

emit dataReceived(queryParams);
Q_EMIT dataReceived(queryParams);
}

} // namespace test_namespace
Loading

0 comments on commit cfe7dcc

Please sign in to comment.