QHttp::Get - Qt Bug gefunden?



  • Folgendes simples Programm führt bei jeder Seite zur einer Fehlermeldung: "Host not found".

    Ich hoffe das sich jemand den Code ansieht, er ist (sollte) leicht verständlich sein!

    Das Programm kompiliert, aber zur Laufzeit gibt es wie oben erwähnt eine Fehlermeldung: "Host http://c-plusplus.net not found"

    //httpget.cpp
    #include "httpget.hpp"
    #include <iostream>
    HttpGET::HttpGET(const QString& strUrl, const quint16 port)
        :m_http(new QHttp(strUrl, port))
    {
        std::cout << "[HttpGET::HttpGET]" << std::endl;
        if(QObject::connect(m_http, SIGNAL(requestFinished(int,bool)), this, SLOT(readData(int, bool))))
            std::cout << "Signal connected" << std::endl;
        else
            std::cout << "Signal not connected" << std::endl;
    }
    HttpGET::~HttpGET()
    {
        delete this->m_http;
    }
    
    void HttpGET::GET(const QString& file)
    {
        this->m_http->get(file);
    }
    
    void HttpGET::readData(int x, bool y)
    {
        if(y)
            std::cout << this->m_http->errorString().toStdString() << std::endl;
        std::cout << this->m_http->readAll().data() << std::endl;
    }
    
    //httpget.hpp
    #ifndef HTTPGET_HPP
    #define HTTPGET_HPP
    
    #include <QtNetwork>
    
    class HttpGET : public QObject
    {
    Q_OBJECT
    public:
        HttpGET(const QString&, const quint16);
        void GET(const QString&);
        ~HttpGET();
    private slots:
        void readData(int, bool);
    private:
        QHttp* m_http;
    };
    
    #endif // HTTPGET_HPP
    
    //main.cpp
    #include <QtCore>
    #include "httpget.hpp"
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        HttpGET obj("http://c-plusplus.net", 80);
        obj.GET("/forum/index-var-.html");
        return a.exec();
    }
    

    Aus der Dokumentation konnte ich nicht mehr rauslesen, weiß jemand was der Fehler sein könnte?



  • QHttp ist als Deprecated markiert. Soll heiße "gibts nur noch dass alter Code kompiliert". Verwende stattdessen QNetworkAccessManager + QNetworkReply.
    Wahrscheinlich ist er nur irritiertm dass du das "http://" vorne hast. Bei mir jedenfalls macht der Code nach Entfernen keine Probleme mehr. Aber eigentlich steht es genau so in den Beispielen in der Doku (also ohne http://)



  • Tja lesen sollte man können

    This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
    
    This class is not part of the Qt GUI Framework Edition.
    

    das mit dem "http://" war richtig. danke!

    aber da der code ja müll ist schaue ich mir die andere klasse an. danke nochmal


Anmelden zum Antworten