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. Encoding and decoding objects
Forum Updated to NodeBB v4.3 + New Features

Encoding and decoding objects

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 634 Views 1 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.
  • R Offline
    R Offline
    rbharadw
    wrote on 29 Jul 2020, 14:00 last edited by
    #1

    Hi..I am looking for some direction how to do save my application and its objects. Quite new to Qt and I have not done this with C++ either (I have used apple and they use something called NSCoder to do this). I am having an application with a few forms to control standard CAD objects that I create (cone, cylinder etc). I want to 1)save my application and its obects 2) Be able to open them again. Its not Qsettings I need, something that will help me encode and decode Objects (not strings, texts etc) which is what most examples I find. Any direction would be appreciated. Thanks in advance.

    O 1 Reply Last reply 29 Jul 2020, 15:08
    0
    • R rbharadw
      29 Jul 2020, 14:00

      Hi..I am looking for some direction how to do save my application and its objects. Quite new to Qt and I have not done this with C++ either (I have used apple and they use something called NSCoder to do this). I am having an application with a few forms to control standard CAD objects that I create (cone, cylinder etc). I want to 1)save my application and its obects 2) Be able to open them again. Its not Qsettings I need, something that will help me encode and decode Objects (not strings, texts etc) which is what most examples I find. Any direction would be appreciated. Thanks in advance.

      O Offline
      O Offline
      ODБOï
      wrote on 29 Jul 2020, 15:08 last edited by ODБOï
      #2

      @rbharadw this links might help
      https://doc.qt.io/qt-5/qdatastream.html
      https://www.qt.io/blog/2018/05/31/serialization-in-and-with-qt
      https://stackoverflow.com/questions/2570679/serialization-with-qt
      https://www.youtube.com/watch?v=JpmnHTM5qX8

      1 Reply Last reply
      3
      • R Offline
        R Offline
        rbharadw
        wrote on 29 Jul 2020, 17:31 last edited by
        #3

        Thank you. I will take a look.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rbharadw
          wrote on 2 Aug 2020, 14:20 last edited by
          #4

          Hi Lelev
          The links were very useful and I managed to write a class object to a file using QDataStream. But I am still lost with doing a few things and wonder if this is very advanced topic to find help online. So, I have a qt application that makes simple CAD objects, like cones and cylinders. Each of them have a specific data in a class and I managed to write them to a file (thanks to the links you provided). When I am trying to open this data, how do I refresh the main window and the forms used with this data? Do I need to delete these objects and create new mainwindow and new forms with this data? (or) do I write these forms as well in files (if so, its not clear how to use QDataStream). Sorry if these are basic questions. But any guidance would be helpful.

          J 1 Reply Last reply 3 Aug 2020, 05:26
          0
          • R rbharadw
            2 Aug 2020, 14:20

            Hi Lelev
            The links were very useful and I managed to write a class object to a file using QDataStream. But I am still lost with doing a few things and wonder if this is very advanced topic to find help online. So, I have a qt application that makes simple CAD objects, like cones and cylinders. Each of them have a specific data in a class and I managed to write them to a file (thanks to the links you provided). When I am trying to open this data, how do I refresh the main window and the forms used with this data? Do I need to delete these objects and create new mainwindow and new forms with this data? (or) do I write these forms as well in files (if so, its not clear how to use QDataStream). Sorry if these are basic questions. But any guidance would be helpful.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 3 Aug 2020, 05:26 last edited by
            #5

            @rbharadw What are these CAD objects? UI widgets?
            There is absolutely no need to recreate the main window.
            You need to create operator>>(...) operators for your CAD objects and then (pseudo-code):

            CAD cad(this);
            stream>>cad;
            cad.show(), // I assume CAD is a widget and you want to show it
            

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • R Offline
              R Offline
              rbharadw
              wrote on 3 Aug 2020, 21:47 last edited by rbharadw 8 Mar 2020, 21:50
              #6

              Hello Jsulm
              I apologies for the very poor description. You are correct, I meant, objects like cones, cylinders etc (Computer Aided Design) that I store them in a class called data (like conegeometry). I use widget forms to show this data, like diameter etc (called conegeometryforms). So what I have figured out so far is to stream the data using QDataStream into a binary file. I can also read from them. But what is not clear to me is how do I update the forms and the openGLwidget. How do people do this? Do they delete all the old forms and then make new ones with the new data? Do I need to make a document class to do this? I am not sure if there is any easier way.

              J 1 Reply Last reply 4 Aug 2020, 04:11
              0
              • R rbharadw
                3 Aug 2020, 21:47

                Hello Jsulm
                I apologies for the very poor description. You are correct, I meant, objects like cones, cylinders etc (Computer Aided Design) that I store them in a class called data (like conegeometry). I use widget forms to show this data, like diameter etc (called conegeometryforms). So what I have figured out so far is to stream the data using QDataStream into a binary file. I can also read from them. But what is not clear to me is how do I update the forms and the openGLwidget. How do people do this? Do they delete all the old forms and then make new ones with the new data? Do I need to make a document class to do this? I am not sure if there is any easier way.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 4 Aug 2020, 04:11 last edited by
                #7

                @rbharadw said in Encoding and decoding objects:

                Do they delete all the old forms and then make new ones with the new data?

                Since I don't know the exact use case I can't really comment on this. You can remove existing objects and add the new ones you read from binary files, or you can update the existing ones, it's up to you. Don't know what exact problem you have with this.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rbharadw
                  wrote on 4 Aug 2020, 11:43 last edited by
                  #8

                  Thank you for all the replies. This was very helpful. No technical issue anymore, just a best practice query.

                  1 Reply Last reply
                  0

                  1/8

                  29 Jul 2020, 14:00

                  • Login

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