Git Product home page Git Product logo

Comments (5)

Skycoder42 avatar Skycoder42 commented on July 2, 2024

QSqlQuery is a very complex type and not easily serializable. It heavily depends on how much of the query you want to serialize. Do you only need the query string, or also possible arguments that have already been set. Do you want to include the result, selection state, drivers etc.

Also, QSqlQuery needs to be constructed with a QSqlDatabase to properly work. Do you want to serialize the connection information of that database as well? Or only the name?

Those are just the basic question you need to answer to solve this. If you only need the pattern, simply convert it to a string and then serialize it. For all other cases, you have to implement a custom QJsonTypeConverter. The documentation gives a details explanation on how to use these. The details of the serialization however you have to figure out yourself, as again, there are way to many possiblities on what exactly you need to serialize.

The same applies for the QSqlQueryModel - what exactly do you want to serialize here?

from qtjsonserializer.

MrAhmedSayedAli avatar MrAhmedSayedAli commented on July 2, 2024

My simple Code i used
just serialize the result to sent it to TCP

QJsonDocument DataBase::toJson(const QString &sqlquery)
{
QJsonDocument json;
QJsonArray recordsArray;
if(QSqlDatabase::contains(ConnName) == false){
if(!dbConnact()){
return json;
}
}
QSqlQuery query(sqlquery,QSqlDatabase::database(ConnName));

while(query.next()) {
    QJsonObject recordObject;
    for(int x=0; x < query.record().count(); x++) {
        recordObject.insert( query.record().fieldName(x), QJsonValue::fromVariant(query.value(x)) );
    }
    recordsArray.push_back(recordObject);
}
json.setArray(recordsArray);
return json;

}

from qtjsonserializer.

Skycoder42 avatar Skycoder42 commented on July 2, 2024

So you want to serialize the result of a query. Your code seems to do that quite well.

To get the same result using this library, create a QJsonTypeConverter. In its implementation, you can put the code you showed here. Then you can register it to the serializer and serialize queries just like any other datatype

from qtjsonserializer.

Skycoder42 avatar Skycoder42 commented on July 2, 2024

You need any more help? If not, I will close this issue

from qtjsonserializer.

MrAhmedSayedAli avatar MrAhmedSayedAli commented on July 2, 2024

no , you can close it , and thanx ^_^

from qtjsonserializer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.