Comments (4)
From Qt doc:
"QNetworkReply is a sequential-access QIODevice, which means that once data is read from the object, it no longer kept by the device. It is therefore the application's responsibility to keep this data if it needs to."
You probably read the data somewhere else first, then try to read them again and pass it to QJson parser.
from qjson.
I checked the code. Everything works fine when the QNetworkReply
is done.
For example:
void Downloader::replyFinished(QNetworkReply* reply)
{
QJson::Parser parser;
bool ok;
QVariant v = parser.parse(reply, &ok);
qDebug() << ok;
qDebug() << v;
}
Works like a charm.
The issue happens with code like this one:
QNetworkReply* reply = m_manager->get(QNetworkRequest(QUrl(url)));
QJson::Parser parser;
bool ok;
QVariant v = parser.parse(reply, &ok);
qDebug() << ok;
qDebug() << v;
In this case ok
will be set to true
and v
will be an empty variant. That happens because the QNetworkReply::atEnd()
returns true inside of JsonScanner::yylex.
The only solution to this problem would be to provide a dedicated Parser::parse(QNetworkReply*, bool*)
that somehow takes advantage of the readyRead()
signal.
Hints/opinions?
from qjson.
The first approach is the correct one. You have to wait for reply to receive all data before accessing them.
In the second example, you send a GET request, which is AFAIK actually started when the method returns to event loop, so when you immediately pass it to QJson, it calls readAll() and receives an empty string. ok
is set to true
because empty string is valid and is correctly parsed into an empty object.
It's your responsibility to ensure that you pass a ready QIODevice
to QJson::Parser
.
from qjson.
I totally agree with you. I'm going to close this issue as a INVALID one.
BTW: this issue was filed by a user a long time ago on the old bug tracking system, but I never had time to look into it.
from qjson.
Related Issues (20)
- Mac CMake
- Test failure: too large exponential: Number is out of range. HOT 4
- New release 0.9.1
- Build help: QJsonObject on Ubuntu 16.04 HOT 1
- Number is out of range: 19 HOT 1
- Add BOM support
- Non-stored Properties are included by QObjectHelper::qobject2qvariant
- Please review PR 107
- How can i do cmake with cross-compiler
- illegal number with scientific notation such as 1.79769313486232e+308
- 2/4 Test #2: testscanner ......................***Failed 0.01 sec [[email protected]] HOT 2
- Qt6 support HOT 3
- Encode String not behaving well with special characters.
- UTF8 QString parse problem
- Can you change the License to MIT? HOT 2
- Error compiling with Mingw 64 HOT 2
- Wrong indenting
- Request for Qt 5 release HOT 1
- CMake config depends on qtgui, while the library actually doesn't need it
- API/ABI changes review for QJson
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qjson.