Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt5Http not working



  • Hello, i've been using Qt5 for a while not but i keep getting errors / it's not working and I tried all kinds of stuff.

    this SEEMS to work, but never actually completes the http request.

    class requests {
    public:
    	auto get(QUrl url)
    	{
    		QNetworkAccessManager nm;
    		QNetworkReply* nr = nm.get(QNetworkRequest(url));
    		while (!nr->isFinished()){
    			qDebug() << nr->isFinished() << nr->error();
    			Sleep(500);
    		}
    		qDebug() << (nr->request()).url();
    	}
    
    private:
    	QNetworkAccessManager *manager;
    	QNetworkRequest request;
    };
    
    

    What is wrong with this? like i'm just requesting this:

    requests().get(QUrl("https://doc.qt.io/qt-5/qnetworkaccessmanager.html#details"));
    

    if anyone knows what's wrong, i appreciate it.


  • Lifetime Qt Champion

    You should not use this blocking wait but connect to QNetworkReplay::finished() or similar. See http://doc.qt.io/qt-5/qnetworkaccessmanager.html#details for more details on how to do it.


Log in to reply