Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Serializing a widget
Forum Updated to NodeBB v4.3 + New Features

Serializing a widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
37 Posts 7 Posters 7.8k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #2

    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.

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    1 Reply Last reply
    0
    • E Offline
      E Offline
      EL-jos
      wrote on last edited by
      #3

      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

      JonBJ 1 Reply Last reply
      0
      • E EL-jos

        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

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #4

        @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?

        1 Reply Last reply
        2
        • E Offline
          E Offline
          EL-jos
          wrote on last edited by
          #5

          @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?

          1. if you know better or a little bit about whatsapp restoration, please explain it to me .

          Thank you

          JonBJ 1 Reply Last reply
          0
          • E EL-jos

            @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?

            1. if you know better or a little bit about whatsapp restoration, please explain it to me .

            Thank you

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #6

            @EL-jos
            OK, sorry, I know nothing about whatsapp. I'd be very surprised if it "serialized widgets", but that's all I can say.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #7

              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 ?

              1 Reply Last reply
              1
              • E Offline
                E Offline
                EL-jos
                wrote on last edited by
                #8

                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?

                1 Reply Last reply
                0
                • 6thC6 Offline
                  6thC6 Offline
                  6thC
                  wrote on last edited by
                  #9

                  Well, first I'd say:
                  General advice is always use prepared statements.
                  Prepare: https://stackoverflow.com/questions/5609245/qsqlquery-prepared-statements-proper-usage

                  More 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.

                  1 Reply Last reply
                  1
                  • E Offline
                    E Offline
                    EL-jos
                    wrote on last edited by
                    #10

                    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

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      EL-jos
                      wrote on last edited by
                      #11

                      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

                      mrjjM 1 Reply Last reply
                      0
                      • E EL-jos

                        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

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @EL-jos
                        Hi
                        For QSQLITE
                        you need to compile nothing or add any libraries.
                        just
                        QT += sql
                        in your .pro file

                        1 Reply Last reply
                        2
                        • E Offline
                          E Offline
                          EL-jos
                          wrote on last edited by
                          #13

                          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?

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            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 ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            1
                            • E Offline
                              E Offline
                              EL-jos
                              wrote on last edited by
                              #15

                              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

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                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 ?

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • E Offline
                                  E Offline
                                  EL-jos
                                  wrote on last edited by
                                  #17

                                  Hi,

                                  Yes I use a server for the dialog between client, this means that if a client'A' sends a message to client'B', it will first go through the server then the server will send me to the destination so client'B'.

                                  1 Reply Last reply
                                  0
                                  • E Offline
                                    E Offline
                                    EL-jos
                                    wrote on last edited by
                                    #18

                                    please someone has an idea.

                                    mrjjM 1 Reply Last reply
                                    0
                                    • E EL-jos

                                      please someone has an idea.

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #19

                                      @EL-jos
                                      About ?

                                      1 Reply Last reply
                                      0
                                      • E Offline
                                        E Offline
                                        EL-jos
                                        wrote on last edited by
                                        #20

                                        In fact I want to make sure that if we send a message to a client that is not connected, that this client sees the message that has been sent as soon as it is connected.

                                        JKSHJ 1 Reply Last reply
                                        0
                                        • E EL-jos

                                          In fact I want to make sure that if we send a message to a client that is not connected, that this client sees the message that has been sent as soon as it is connected.

                                          JKSHJ Offline
                                          JKSHJ Offline
                                          JKSH
                                          Moderators
                                          wrote on last edited by JKSH
                                          #21

                                          @EL-jos said in Serializing a widget:

                                          I want to make sure that if we send a message to a client that is not connected, that this client sees the message that has been sent as soon as it is connected.

                                          Then the central server must store the message. When the client comes online, the server can deliver the message to the client.

                                          Note: This concept is about communications architecture. This is not related to widgets at all.

                                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                          1 Reply Last reply
                                          2

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved