Comments (4)
The easiest way would be to simply remove all unneeded types from the src/jsonserializer/typesplit.pri file.
You could even remove almost everything from the file if you don't want anything registered at all. However, the generation of the primary hook itself must remain, even as empty function, as otherwise there will be linker errors. That would reduce the file to the following:
isEmpty(QT_JSONSERIALIZER_REGPATH): QT_JSONSERIALIZER_REGPATH = $$OUT_PWD/.reggen
mkpath($$QT_JSONSERIALIZER_REGPATH)
startup_hookfile = "void qtJsonSerializerRegisterTypes() {}"
out_file = $$QT_JSONSERIALIZER_REGPATH/qjsonconverterreg_all.cpp
!exists($$out_file):!write_file($$out_file, startup_hookfile):error("Failed to create $$out_file")
GENERATED_SOURCES += $$out_file
from qtjsonserializer.
Thanks for the code.
It drastically reduced the binary size but I see that all the de/serialize processes in my code are working well even with nothing being registered and I don't know why.
Another thing that crossed my mind was removing type converters that I don't need in typeconverters.pri.
I wanted to know what are those files and ask if it is ok to remove them?
I would appreciate it if you describe the mechanism of type converters and their registrations.
from qtjsonserializer.
The library basically has two kinds of conversion (which, unfortunately, are all named "typeconverters" due to a shortsight of mine)
- Container converters
- Serializers
Container converters
The first group is what is generated with the typesplit.pri
file and is responsible for generalizing generic types, e.g.:
QList<int> <=> QVariantList
QMap<QString, double> <=> QVariantMap
....
This allows the library to de/serialize any generic type, as long as such a converter has been registered for that type. You can register those manually via QJsonSerializer::register*
methods. Please note that this part has drastically changed with the 4.0.0 release and is no longer valid, but for your version, that's the task these methods (and the startup hook) have.
Removing the hook simply means, that you cannot convert generic containers anymore. If you have for example a QList<int>
somewhere, it will stop working, unless you manually call QJsonSerializer::registerListConverters<int>
in your code. The hook is simply provided to automatically do these registrations for common Qt types so you don't have to.
Serializers
The QJsonTypeConverter
classes in contrast are responsible for doing the actual conversion between C++ and JSON. Some basic types are converted implicitly, but most types, (e.g. lists, objects, ...) need a converter. This split between the core serializer and the converters makes the library flexible and easy to extend.
Some of these converters require a certain "Container converter" to be registered for work. For example, the QJsonListConverter
can de/serialize any QList<T>
, as long as T
was registered via QJsonSerializer::registerListConverters<T>
. It can also work with QVariantList
, so if you want to avoid the conversion all together, use QVariantList
properties and you are good.
You can simply remove any converter from typeconverters.pri
you don't need, e.g. if you do not use QVersionNumber
, you can remove the QJsonVersionNumberConverter
. Remove the header and source file from typeconverters.pri
and remove the include and registration from the qjsonserializer.cpp
file.
from qtjsonserializer.
Thanks for the complete clarification and your time.
from qtjsonserializer.
Related Issues (20)
- QHash<int, QString> workaround HOT 2
- It can't convert QSharedPointer successfully.
- How to deserialize derived classes that use none-default constructors HOT 2
- Mac build "make" step giving .reggen errors. Any advice? HOT 2
- Add module fail HOT 1
- Using multiple instances in Qt subdir HOT 3
- Q_GADGET and QVariantList HOT 1
- Deserialization QPair within QVariant
- Cannot find missing dependency "qt.qt5.5130.android_arm64_v8a" ...
- Runtime exception occurred in sample.
- Sample: SerializationException (Unable to determine typeid of meta enum SampleObject::SuperFlags) HOT 1
- Converting QtJsonSerializer from QMake to CMake HOT 1
- Add entries in the repository for Qt 5.15.* and 6
- CopperSpice support HOT 2
- head of line cannot run sample application HOT 1
- Can not serialize enum properties HOT 3
- Poor performance for array of PODs with simple properties
- registerSetConverters results in build time error no matching function to call qHash(...
- Deserialize into existing object
- Create references to existing object , not duplicates HOT 3
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 qtjsonserializer.