I am trying to make a GET request, but Qt says that getData should return an int , although I don’t return .

 #include "downloader.h" Downloader::Downloader(QObject *parent) : QObject(parent) { manager = new QNetworkAccessManager(); } Downloader::getData() { QUrl url("http://www.mtbank.by/currxml.php"); QNetworkRequest request; request.setUrl(url); manager->get(request); } class Downloader : public QObject { Q_OBJECT public: explicit Downloader(QObject *parent = 0); private: QNetworkAccessManager *manager; public slots: void getData(); }; 

Error text:

 prototype for 'int Downloader::getData()' does not match any class 'Downloader' in file included from ../untitled2/downloader.cpp:1:0: candidate is: voidDownloader::getData() void getData(); ^ 
  • 2
    Downloader::getData() - what is it? Where did your void suddenly go? - AnT
  • one
    Give the literal text of the message from the compiler. - αλεχολυτ

1 answer 1

If the function is declared so that it returns non- void , the standard directly requires that all execution paths in it end with either return , or throw , or by stopping the process. The function can not end with "nothing".

Exceptions are the main function. The absence of an explicit return from it is equivalent to return 0;

In connection with the addition of the question:

From the text of the error, it follows that your implementation signature does not match the declaration signature. Make it match:

 class Downloader ... { void Downloader::getData() } .... void Downloader::getData() { } 
  • well, I explicitly asked void, and the compiler says that I make it Int - Radzhab
  • Elahs, how difficult it is .. and how to be? - Radzhab
  • @Radzhab about the virtual method, I guessed wrong. Show the text of errors. - gbg
  • one
    @alexolut If the function does not end with return, but something must return, it will be UB. - gbg
  • one
    @gbg is optional. You can exit and exit or through an exception. - αλεχολυτ