Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How make QIODevice::writeData work asynchronously?
Qt 6.11 is out! See what's new in the release blog

How make QIODevice::writeData work asynchronously?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
13 Posts 3 Posters 3.8k 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.
  • F fpartl

    Hello all,

    I am developing app that record audio using QAudioInput and then pass it to to my class witchis inherited from QIODevice. I have reimplemented the QIODevice::writeData method. There I make my memcopy and calculations. Problem is when I launch the app it is working but GUI is stucked. I tought the QIODevice should work implicitly in different thread. I dont know how to solve this problem. Thank you for help.

    Best regards, fpartl,

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @fpartl said in How make QIODevice::writeData work asynchronously?:

    QIODevice::writeData

    No, it does not work in a different thread. You would need to move writing to file into a different thread.

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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fpartl
      wrote on last edited by
      #3

      Ok. Can you please tell me how to move my QIODevice to another thread?

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

        Hi,

        The QObject::moveToThread function might be what you need.

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

          Thank you for reply. I dont know if I should move to thred whole class with QAudioInput a QIODevice objects or just QIODevice. I will try something.

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

            Usually you move the whole object, don't forget to parent things correctly to have everything moved properly.

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

              I have done the work. I have created the the AudioWorker class witch inherits QObject. Then I maked QAudioInput and QIODevice in here and I make a forward of signals from QIODevice to catch calculated data. I moved AudioWorker to QThread and pressed the Run button. But program crash on segmentation fault in QIODevice even if I comment the whole code in writeData method.

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

                Without the code and the backtrace, it's pretty much Crystal Ball Debugging so here goes: did you check that you have everything initialised properly before using ?

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

                  Ou, I am sorry. The code is on GitHub. I wrote the AudioWorker class and program fails after I close the MainWindow with

                  The program has unexpectedly finished.
                  C:\Users\frant\QtProjects\build-PocketEar-Desktop_Qt_5_8_0_MinGW_32bit-Debug\debug\PocketEar.exe crashed.
                  

                  In the AudioWorker there is instances of QAudioInput and QIODevice(MFCCPerformer).
                  In the debug mode I got segmentation fault after MainWindow close on line 28 in AudioWorker (audioInput->suspend()). I think I am wrong with a closing of the thread. Thank for help.

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

                    Do you have a complete stack trace ?

                    Note that you are doing a double delete with audioInput and mfcc. Both of them have a parent so they will be delete when AudioWorker gets deleted.

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

                      Here is a stack trace after failure. I really appreciate your help. I am new in this problematics.

                      Stack trace

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        fpartl
                        wrote on last edited by
                        #12

                        I figured it out! serverStateChanged call pause method on alredy destroyed object. Now it works. What a thing! Thank you for help! :-)

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

                          You're welcome !

                          Since you have found the error, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

                          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

                          • Login

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