Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. curl returning none of the HTML content
Forum Updated to NodeBB v4.3 + New Features

curl returning none of the HTML content

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
4 Posts 2 Posters 414 Views
  • 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.
  • H Offline
    H Offline
    hecker
    wrote on last edited by hecker
    #1

    Hi, I'm having a problem with curl, the content of the HTML being written is: "".
    I believe that the problem is related to the installation since the same code works perfectly in visual studio code.

    My curl installation:

    QT       += core gui sql
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++17
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    LIBS += "C:/Users/uique/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Qt/6.4.0/MinGW 11.2.0 (64-bit)/lib/libcurl.a"
    LIBS += "C:/Users/uique/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Qt/6.4.0/MinGW 11.2.0 (64-bit)/lib/libcurl.dll.a"
    INCLUDEPATH += "C:/Users/uique/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Qt/6.4.0/MinGW 11.2.0 (64-bit)/includer/curl"
    
    
    SOURCES += \
        add_order.cpp \
        login.cpp \
        main.cpp \
        mainwindow.cpp \
        wallet.cpp
    
    HEADERS += \
        Global_variables.h \
        add_order.h \
        login.h \
        mainwindow.h \
        wallet.h
    
    FORMS += \
        add_order.ui \
        login.ui \
        mainwindow.ui \
        wallet.ui
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    RESOURCES += \
        Resources.qrc
    
    

    my function that is using curl:

    void MainWindow::update_tb(){
        CURL *curl;
        CURLcode res;
        std::string HTMLcontent;
        curl = curl_easy_init();
        if(curl){
            curl_easy_setopt(curl, CURLOPT_URL, "https://api.binance.com/api/v3/ticker/price");
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeHTML);
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, &HTMLcontent);
            res = curl_easy_perform(curl);
    
            curl_easy_cleanup(curl);
            qDebug() << QString::fromStdString(HTMLcontent);
        }
        //qDebug() << QString::fromStdString(HTMLcontent);
        QSqlQuery query;
        std::string content = HTMLcontent;
        std::string pattern = "\\{\"symbol\":\"(.+?)\",\"price\":\"(.*?)\"\\}";
        std::regex rule(pattern);
        std::smatch match;
    
        while(std::regex_search(content, match, rule)){
    
            query.prepare("update coins_tb set VALUE='"+QString::fromStdString(match.str(2))+"' where TOKEN='"+QString::fromStdString(match.str(1))+"'");
            if(!query.exec()){
                QMessageBox::warning(this, "Erro", "Erro ao atualizar banco de dados");
            }
        }
    
    
        int row = 0;
    
    
        query.prepare("select VALUE from coins_tb where TOKEN like'%"+ui->lineEdit_filter->text()+"%'");
        if(!query.exec()){
        }else{
            query.first();
            do{
                ui->tw_tokens_list->setItem(row, 1, new QTableWidgetItem(query.value(0).toString()));
                row++;
            }while(query.next());
    
             if(ui->tw_tokens_list->currentRow() > -1){
                ui->label_value->setText(Global_var::token_value);
             }
    
        }
    }
    

    function responsible for writing the HTML count in the variable:

    size_t writeHTML(char* HTML_content, size_t char_size, size_t char_amount, char* buffer_in) {
        size_t bytes = char_size * char_amount;
        ((std::string*)buffer_in)->append((char*)HTML_content, bytes);
    
    
        return bytes;
    }
    

    include and function prototype:

    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "add_order.h"
    #include "Global_variables.h"
    #include "login.h"
    #include "wallet.h"
    #include <QDebug>
    #include "curl/curl.h"
    #include <regex>
    
    
    QString Global_var::current_token;
    QString Global_var::token_value;
    bool Global_var::login = false;
    
    size_t writeHTML(char* HTML_content, size_t char_size, size_t char_amount, char* buffer_in);
    
    
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use a debugger, see what's happening.
      Also please don't post pictures but text.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      H 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Use a debugger, see what's happening.
        Also please don't post pictures but text.

        H Offline
        H Offline
        hecker
        wrote on last edited by
        #3

        @Christian-Ehrlicher Debugg returns "" from HTMLcontent

        Christian EhrlicherC 1 Reply Last reply
        0
        • H hecker

          @Christian-Ehrlicher Debugg returns "" from HTMLcontent

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @hecker said in curl returning none of the HTML content:

          Debugg returns "" from HTMLcontent

          I said you should use a debugger, not print something out.
          Make a breakpoint in your writeHTML()m function to see if it's called and what's going on in there.

          Don't know whjat this has to do with Qt though...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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