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. [Solved] Save for QGenericMatrix
Forum Updated to NodeBB v4.3 + New Features

[Solved] Save for QGenericMatrix

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 3.4k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    buffer is not initialized

    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
    • D Offline
      D Offline
      doubitchou
      wrote on last edited by
      #5

      Indeed,but there is not a better way to parse and save it to a file ?
      I was mostly thinking about iterate through the matrix for example,

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

        Why not use:

        @
        QFile file(filename);
        //file open and check
        QDataStream stream(&file);
        stream << myMatrix;
        @

        ?

        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
        • D Offline
          D Offline
          doubitchou
          wrote on last edited by
          #7

          Thought there were something different.
          Ok, thank you Samuel

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

            Do you mean more simple/complicated/verbose ?

            You're welcome

            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
            • D Offline
              D Offline
              doubitchou
              wrote on last edited by
              #9

              well....yes ;) something more verbose, this simplicity is puzzling. I don't say it's good or wrong but I was thinking about something traversing the matrix like an iterator. Afterall, it does it anyway.

              Edit : I couldn't have the matrix representation in the hex file. For instance, save the matrix only will be ok if I use an array like this:

              @int MyClass::Save_To_File(QString Filename)
              {
              int val[20]={};
              unsigned short index ;
              QDataStream out(&File_Ptr) ;
              QFile File_Ptr(Filename) ;

              MyMatrix.copyDataTo( val );

              if (!File_Ptr.open(QIODevice::WriteOnly ) )
              return 1 ;

              for ( index=0; index<20;index++)
              {
              out << (unsigned char)(val[index]) ;
              }
              File_Ptr.close();
              return 0 ;
              }@

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

                What do you mean by "I couldn’t have the matrix representation in the hex file" ?

                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
                • D Offline
                  D Offline
                  doubitchou
                  wrote on last edited by
                  #11

                  yes, I should have been more explicit: when I use the same class than previously writen with the 1s cell containin '1' ie, matrix[0][0]=1 looking it with hexdump :
                  000000 0100 0000 ....
                  while changing the code with :
                  out << MyMatrix ;

                  change the same data in hexdump to :
                  000000 f03f 0000 ....

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

                    One of the problem that you have is that you are casting an int to an unsigned char which are not the same size so you could be losing data at some point. The stream operator sends the matrix content as double to the stream.

                    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
                    • D Offline
                      D Offline
                      doubitchou
                      wrote on last edited by
                      #13

                      Actually the working code is the one in the post here using the cast , And if I comment that code to use
                      @stream << myMatrix;@

                      Instead of writing 0100 the file contains f03f

                      1 Reply Last reply
                      0

                      • Login

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