Comments (6)
I am not shure where you went wrong, because your declarations at least include the correct declarations. The only ones you need are a list converter for the SaleProperty
followed by a map converter for a list of those:
QJsonSerializer::registerListConverters<SaleProperty*>();
QJsonSerializer::registerMapConverters<QList<SaleProperty*>>();
qRegisterMetaType
is not needed, as QMap
and QList
are already declared for any type, you only need a Q_DECLARE_METATYPE(SaleProperty*)
In the header.
The libraries uses exceptions, so to find out what exactly goes wrong, you should try to catch and print them. The "quick and dirty" way is to just do so in the main:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
try {
// <Your code>
return a.exec();
} catch (QJsonSerializerException &e) {
qCritical("%s", e.what());
return 1;
}
}
I created a basic demo project to check if there was actually some error in the library, but my test project worked as expected. I attached it so you can compare it with your code: jserissue.zip
from qtjsonserializer.
Hello,
qRegisterMetaType<SaleProperty*>("SaleProperty*");
Before using it.
Hope this will help,
Good luck!
from qtjsonserializer.
I am not shure where you went wrong, because your declarations at least include the correct declarations. The only ones you need are a list converter for the
SaleProperty
followed by a map converter for a list of those:QJsonSerializer::registerListConverters<SaleProperty*>(); QJsonSerializer::registerMapConverters<QList<SaleProperty*>>();
qRegisterMetaType
is not needed, asQMap
andQList
are already declared for any type, you only need aQ_DECLARE_METATYPE(SaleProperty*)
In the header.The libraries uses exceptions, so to find out what exactly goes wrong, you should try to catch and print them. The "quick and dirty" way is to just do so in the main:
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); try { // <Your code> return a.exec(); } catch (QJsonSerializerException &e) { qCritical("%s", e.what()); return 1; } }
I created a basic demo project to check if there was actually some error in the library, but my test project worked as expected. I attached it so you can compare it with your code: jserissue.zip
Thanks a lot.
I checked my code again, and found that i was using Q_DECLARE_METATYPE(SaleProperty) in my header file, and when i changed it to Q_DECLARE_METATYPE(SaleProperty*), everything went well.
i do not usually use these advance macro, at first, i considered that pointer dose not seem to need specially declare after i read the README.md document. so i think, because of qt do not recognize self-define class so i use Q_DECLARE_METATYPE(SaleProperty) in my header file. is there anything i understand wrong?
is there anything i understand wrong?
from qtjsonserializer.
Hello,
qRegisterMetaType<SaleProperty*>("SaleProperty*");
Before using it.Hope this will help,
Good luck!
thank you for your help, and i also solved my problem, good luck
from qtjsonserializer.
Q_DECLARE_METATYPE(SaleProperty)
is wrong in this context, if SaleProperty is a Q_OBJECT
.
The rule is:
- Class extends
QObject
and has theQ_OBJECT
macro -> UseQ_DECLARE_METATYPE(MyClass*)
- Class is a normal, value type class/struct and has the
Q_GADGET
macro -> useQ_DECLARE_METATYPE(MyClass)
- Generally speaking, register the type in the way you use it in your code
Whether registering is required or not often depends on the context and usage, and at least for this very basic example, it would not be strictly neccessary, but it's always good to use those macros anyway, as having them is always only beneficial.
I will close this issue know, but if you have further questions regarding this specific case, you can still reply to it.
from qtjsonserializer.
Q_DECLARE_METATYPE(SaleProperty)
is wrong in this context, if SaleProperty is aQ_OBJECT
.The rule is:
- Class extends
QObject
and has theQ_OBJECT
macro -> UseQ_DECLARE_METATYPE(MyClass*)
- Class is a normal, value type class/struct and has the
Q_GADGET
macro -> useQ_DECLARE_METATYPE(MyClass)
- Generally speaking, register the type in the way you use it in your code
Whether registering is required or not often depends on the context and usage, and at least for this very basic example, it would not be strictly neccessary, but it's always good to use those macros anyway, as having them is always only beneficial.
I will close this issue know, but if you have further questions regarding this specific case, you can still reply to it.
Thanks again, I've learned a lot from your help. Have a nice day
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.