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. Qt Load and Save media with QDataStream
Forum Updated to NodeBB v4.3 + New Features

Qt Load and Save media with QDataStream

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 851 Views 2 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
    #2

    Hi,

    So you want to store some random files in an archive to then reload that archive on another computer with your application ?

    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
    • G Offline
      G Offline
      GeminiMan
      wrote on last edited by
      #3

      No what i want for example when i open dialog file and i select sound.mp3 the application load the sound in variable like mysound and save it in file "myproject.dat" by using the QDataStream. in this way i dont need an archive, just load my file "myproject.dat".

      mrjjM 1 Reply Last reply
      0
      • G GeminiMan

        No what i want for example when i open dialog file and i select sound.mp3 the application load the sound in variable like mysound and save it in file "myproject.dat" by using the QDataStream. in this way i dont need an archive, just load my file "myproject.dat".

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

        @GeminiMan
        Hi why not use an external resource file to store the sounds and movies in ?
        https://doc.qt.io/qt-5/resources.html

        Qt can load files directly from such at runtime.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GeminiMan
          wrote on last edited by
          #5

          No this is not what is required in the work, what they want is selection of media from Filedialog and stored in memory or saved in the project file as in the editing software, it is enough just to reload the project file and you have all the project.

          mrjjM 1 Reply Last reply
          0
          • G GeminiMan

            No this is not what is required in the work, what they want is selection of media from Filedialog and stored in memory or saved in the project file as in the editing software, it is enough just to reload the project file and you have all the project.

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

            @GeminiMan
            Hi
            Well you can use QDataStream to store all other files into one big fat binary .dat file but
            to use them again, will be hell as QListWidget won't take it directly from some
            big file. you would have to very carefully read it back to its original types for Qt to be able to use it.

            So basically you want to develop sort of your on big media file format where one files stores
            other files ?

            Just trying to understand what the goal is as it seems kinda odd.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              GeminiMan
              wrote on last edited by
              #7

              yeah exactly one file contains all media don't worry about file size they want to limit media size for video 10 Mo
              image 5 mo and sound 10mo.

              projectfile.projet contains:
              -Images
              -Videos
              -Audio

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

                Hi
                Well that should be possible to do with QDataStream but for
                sound and movies, you will need
                to include a header pr item telling size so you know how much to read pr item for reading them back.
                You can write any binary with
                https://doc.qt.io/qt-5/qdatastream.html#writeRawData

                However, Im not sure how easy it will be to actually play the data back as
                it not 100% sure Qt Multimedia will allow to directly play from a binary file of custom format.
                So you might need to write them back to a temporary file to play it.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  GeminiMan
                  wrote on last edited by
                  #9

                  But how i can get the sound and video ? the image i know with QImage

                  mrjjM 1 Reply Last reply
                  0
                  • G GeminiMan

                    But how i can get the sound and video ? the image i know with QImage

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

                    @GeminiMan
                    Well im not sure its possible even it does accept a buffer
                    https://stackoverflow.com/questions/42168280/qmediaplayer-play-a-sound-loaded-into-memory

                    But maybe the new gst-pipeline: appsrc will allow it
                    https://doc.qt.io/qt-5/qmediaplayer.html#setMedia

                    But its not something i have experience with.

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

                      Get them from what ?

                      The model view system does not provide special handling for every possible datatypes. Images are a special case because of the decoration role that allows to show them but that 's nice coincidence. It seems you try to reinvent something like HDF5 or Qt's resource system.

                      You are trying to completely mix the model and the data themselves. if you want to have a view on top of your custom data file, then you will have to implement a model yourself that is able to parse your custom file and provide it's content in that memory only representation you want. But even so, if you want to show your user some video, you'll have to put in disk somewhere as not all platform multimedia backends may support playing from memory.

                      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
                      • G Offline
                        G Offline
                        GeminiMan
                        wrote on last edited by
                        #12

                        you are off topic @SGaist.
                        QListWidget is here just to display the name and icon of the media loading, thank you @mrjj this is what I was looking for play a sound or video loaded into memory is QMediaPlayer and QBuffer. QBuffer you used into QDataStream to save.

                        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