qt class lib rest api
-
Hi everyboy i wanna to make class library to rest api with model like c# what i mean that i have created shared class lib and add my methods there with add data , update and delete .... and created my functions for that i need to make mdel with all properties wherei can p[ass json result to theese items or properties i use qt and c++
my mainclass.h method is
//Method to genrate token std::string GenerateToken( QString& Uname, QString& password);
my main .cpp
std::string MicrosoftGraph::GenerateToken( QString& Uname, QString& password)
{
QNetworkAccessManager * manager = new QNetworkAccessManager();
QByteArray jsonDocument("{}");QUrl url("https://google.com/oauth2/token"); QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QUrlQuery params; params.addQueryItem("username", Uname); params.addQueryItem("password", password); QNetworkReply* reply = manager->post(request, params.query().toUtf8()); std::cout << "Ok, Server response : " << reply << std::endl; std::string token = "tahnks"; return token;
}
what i need as i mentioned to get return to variable whuch declared like model in c#
for example in header file
namespace getdata {
struct Body { QString token; QString msg; };
}
-
Hi,
First thing: you are leaking QNetworkAccessManager objects for each call to GenerateToken.
Qt is asynchronous so you want to have a slot or a lambda to parse the answer.
Not knowing what you want to do with that structure, its not possible to give further advices.
-
@SGaist Thanks for response what i try to do is try to make c++ library to get and post api data and return result which comes from json . json contain many value which i try to return all values like models in c# then i will use it in my c# application
-
You might also want to check the Cutelyst project.
-
Then you mean you want a synchronous behaviour ?
If so, you can use QEventLoop to "block the execution flow". Do not forget to take into account error management.