Answer the question
In order to leave comments, you need to log in
C++, the compiler is behaving strangely or am I missing something?
I can't figure out why this code throws an error:
QNetworkRequest request();
request.setRawHeader("", "");
error: request for member 'setRawHeader' in 'request', which is of non-class type 'QNetworkRequest()'
QString s = "test";
QNetworkRequest request(QUrl(s));
request.setRawHeader("", "");
error: request for member 'setRawHeader' in 'request', which is of non-class type 'QNetworkRequest(QUrl)
QUrl reqUrl(url);
QNetworkRequest req(reqUrl);
QNetworkRequest req(QUrl("some_url"));
Answer the question
In order to leave comments, you need to log in
The first example is a classic mistake, the compiler is right - you actually wrote a function.
Parentheses are not required to declare a class and call the default constructor.
Even Carmack rode this one :
The fact that ScopedLock lock() is a function declaration and not a parameterless constructor call made me more upset today.
Unfortunately, for the compiler, the second case also looks like a function declaration.
The req function accepting one parameter (for more details, follow the link).
The first option you suggested is a great way out of this situation. You can also write like this:
Upd: I found a detailed description of this error from Meyers.
In the first case, you declared a function, not a class object.
In the second case, there is no such function (setRawHeader(QSting, QString)).
Try like this:
QString s = "test";
QNetworkRequest request(QUrl(s));
request.setRawHeader(QByteArray(""), QByteArray(""));
QNetworkRequest request;
request.setRawHeader("", "");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question