简体   繁体   English

没有用于初始化“ QNetworkRequest”的匹配构造函数

[英]no matching constructor for initialization of 'QNetworkRequest'

Im trying to get the content of web page so I parse all the divs and create a text file of that, here my starting code, 我正在尝试获取网页的内容,因此我解析了所有div并创建了一个文本文件,这里是我的起始代码,

      #include <QCoreApplication>
      #include <QNetworkAccessManager>
      #include <QNetworkRequest>
      #include <QNetworkReply>
      #include <QUrl>


      int main(int argc, char *argv[])
       {
            QCoreApplication a(argc, argv);

            QNetworkRequest* request = new QNetworkRequest("http://en.wikipedia.org/wiki/Cars");


       return a.exec();
     }

I got this error : no matching constructor for initialization of 'QNetworkRequest' whats wrong 我收到此错误:“ QNetworkRequest”的初始化没有匹配的构造函数怎么了?

please help thanks in advance 请提前帮助谢谢

QNewtorkRequest takes a QUrl object in its constructor. QNewtorkRequest在其构造函数中使用一个QUrl对象。 You can use : 您可以使用 :

QNetworkRequest* request = new QNetworkRequest(QUrl("http://en.wikipedia.org/wiki/Cars"));

Check out Qt's doc if you want to check out which arguments are taken into constructors. 如果您想查看哪些参数被带入构造函数,请查看Qt的文档。 If you use QtCreator, the doc is embedded and it usually will inform you of the possible types you can give to functions as parameters. 如果您使用QtCreator,则文档将被嵌入,并且通常会通知您可以作为参数的函数的可能类型。

QUrl wikiUrl("http://en.wikipedia.org/wiki/Cars");
QNetworkRequest* request = new QNetworkRequest(wikiUrl);

The above should work. 以上应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM