Serializing a widget
-
Hey, everybody,
As part of my chatt software, I will know how whatsapp(on PC) does to play back the message as soon as the client is online?
here's a picture:
so I thought about serializing my QWidget (which is used to display conversations between customers) in a database.
here are my questions:
- Is it possible to serialize a QWidget and its children in a database?
- if that is possible how can I do it?
Thanks in advance for your help
-
You can take all the properties of widget and save them. You can use QSettings for the same as well. There is nothing like serialising the Widget.
-
Thank you for your answer,
But where can you get these properties? and how can you save them in a database?
I prefer to save the QWidget properties in a database
@EL-jos
Up to you. But whatsapp is not going to be serializing widgets or even saving their properties. Don't know what you want to achieve exactly, but can't you just save whatever data you need to reconstruct a message (content, datetime), and resurrect from that? -
@JonB said in Serializing a widget:
Up to you. But whatsapp is not going to be serializing widgets or even saving their properties. Don't know what you want to achieve exactly, but can't you just save whatever data you need to reconstruct a message (content, datetime), and resurrect from that?
So if I understand very well you ask me to save just the elements I need such as(message, date and time,); but how to do for positioning?
- if you know better or a little bit about whatsapp restoration, please explain it to me .
Thank you
-
@JonB said in Serializing a widget:
Up to you. But whatsapp is not going to be serializing widgets or even saving their properties. Don't know what you want to achieve exactly, but can't you just save whatever data you need to reconstruct a message (content, datetime), and resurrect from that?
So if I understand very well you ask me to save just the elements I need such as(message, date and time,); but how to do for positioning?
- if you know better or a little bit about whatsapp restoration, please explain it to me .
Thank you
-
Hi
For each message , date and time, you would save and index number telling
where in conversation it comes and some sort of ID for the message .
and most likely also a conversation id.So you store the messages in one table
TABLE: messages
msgID, message text,
msgID, message text, etc
and make a table to list
conversation id, msgID
In other table
and most likely the persons also in other table with reference to conversations they
have taken part in.But how are your data structured now ?
-
in fact for the data structure when I try to create a table and its values it does not work, here is my query:
base = QSqlDatabase::addDatabase("QSQLITE"); base.setDatabaseName("AMIS"); if(base.open()){ QSqlQuery query(base); qDebug() << query.exec("CREATE TABLE `test`.`amis` ( `id` INT NOT NULL AUTO_INCREMENT , `nom` VARCHAR(20) NOT NULL , `image` BLOB NOT NULL , PRIMARY KEY (`id`)) "); }
I always have false as the answer to the console output so my table is not created,
I even tried to remove the apostrophes on name, id and image but it still doesn't work.
Anybody got any ideas?
-
Well, first I'd say:
General advice is always use prepared statements.
Prepare: https://stackoverflow.com/questions/5609245/qsqlquery-prepared-statements-proper-usageMore general advice is figure out the actual query you sent the engine by firing a verbatim copy of the query generated in your application directly @ the engine without the application.
So, how I see it:
- Determine the actual statement
- run it at the engine (using with command line or query / db engine tools and see the response - independent from your application anyhow).
- Witness the engine response as a result of your statement (I'm expecting a syntax error as it seems you are too)
- This will lead you to the reasons what is not being correctly done in your application.
- Fix the application statement
- Try again
I suspect it would be a parsing error as you're playing with the single quotes but cannot say. I also won't troubleshoot what seems just syntax/parsing... that's for you to determine / observe.
-
Hey, family,
After a lot of testing, I understood that my database and my amis table are created but except that the amis table contains no columns so no fields.
I tried to add the plugin qsqlited.dll and qsqlmysqld.dll since I compiled in debug mode but my amis table is still empty so no amis.
Here's my code:QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("base_de_donnees2.db"); db.open(); if(!db.isOpen()) qDebug() << "ERREUR d'ouverture de la base de données; cause: " << db.lastError().text(); QSqlQuery q; q.exec("CREATE TABLE IF NOT EXISTS amis (id INTEGER PRIMARY KEY AUTOINCREMENT, nom TEXT NOT NULL, photo BLOB NOT NULL) "); QSqlQuery q2; q2.prepare("INSERT INTO amis (id,nom,photo) VALUES (:id,:nom,:photo) "); int identifiant = 1; QString pseudo("EL-chrino"); QFile fichier(QFileDialog::getOpenFileName()); fichier.open(QIODevice::ReadOnly); QByteArray byte; if(!fichier.isOpen()) qDebug() << "Echec d'ouverture du fichier"; byte = fichier.readAll(); q2.bindValue(":id",identifiant); q2.bindValue(":nom",pseudo); q2.bindValue(":photo",byte); if(!q2.exec()) qDebug() << "ERREUR lors de l'exécution de la requête; cause: " << q2.lastError().text();
Note that I have never used databases with Qt so I don't know how it works, please tell me what I need to do to use databases with Qt as it will be very important for my chatt software.
Thank you in advance -
I found in a forum, they say you need to recompile Qt and SQL Drive but it doesn't explain how to do it.
Please if there is someone who knows how to make it watch you manifest
-
Thank you very much for your advice, but I have two questions;
first how to update a QscrollArea that already contains elements beforehand?
and the second is how to make a message waiting list like this if a client "A" has just logged out and another client "B" sends him a message, that the message is in a list to wait for the client "A" to read it.
like whatsapp or facebook notification when someone sends us a message while we're away, the message is kept until we read it? -
Hi,
You just append new widgets to the layout that already contains the others.
As for the messages, if you are thinking on how it’s working on mobile platform, you’ll have several things to take into consideration.
So some questions for you:
- On what platform(s) is your application going to run ?
- How are the client going to talk to each other ?
-
Regarding the update of my scroollArea, I don't want to add elements but rather delete completely what it already contains.
then for the messages I want my application to run all over the platform but first on Pc using the windows operating system.
for my clients, I use TCP/ip protocol so with QTcpSocket class
-
The most elegant would likely be to have the messages stored in a model and then have a custom QStyledItemDelegate to paint whatever you want.
Again: how are you client talking to each other ? Through a central server ? How do they know each other ?