Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qt class lib rest api
Qt 6.11 is out! See what's new in the release blog

qt class lib rest api

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 520 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr.alaa
    wrote on last edited by Mr.alaa
    #1

    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;
      };
    

    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      1
      • SGaistS SGaist

        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.

        M Offline
        M Offline
        Mr.alaa
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You might also want to check the Cutelyst project.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          M 1 Reply Last reply
          0
          • SGaistS SGaist

            You might also want to check the Cutelyst project.

            M Offline
            M Offline
            Mr.alaa
            wrote on last edited by
            #5

            @SGaist I try to make c++ library

            where i can call functions to excute apsi

            to get ot post data and return resul

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved