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. WaitForBytesWritten crashes
Forum Update on Monday, May 27th 2025

WaitForBytesWritten crashes

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.7k Views
  • 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
    RogueWarrior
    wrote on last edited by
    #1

    I've got some code that uses QTCPSocket and writes some data to it. After I write the data, I call wait for waitForBytesWritten(1000). The code runs for several seconds and then crashes. Note: I take the instance of the class and call moveToThread so perhaps threading has something to do with it.

    One of the error messages is of this form:
    malloc: *** error for object 0x101022400: pointer being freed was not allocated

    Other runs of the same code might produce this error:
    malloc: *** error for object 0x100915b10: double free

    Also note that what I'm doing is talking to a serial port over the network via ser2net. If I run this locally using QSerialPort, I have the same problem so the crash happens in QIODevice.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BlastDV
      wrote on last edited by
      #2

      Hi RogueWarrior, why and how are you calling moveToThread() ?

      (8) Just live your life blind like me (8)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RogueWarrior
        wrote on last edited by
        #3
            QThread *my_thread = new QThread;
            myIODeviceThing->moveToThread(my_thread);
            my_thread->start();
            QMetaObject::invokeMethod(myIODeviceThing, "MySlot", Qt::QueuedConnection);
        

        Followup:
        It appears that writing to the device too fast has something to do with it.
        I added an msleep(50) to the code and I haven't seen the crash. That said, it doesn't really explain the problem. Maybe there isn't proper buffer overflow protection in the QIODevice code.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BlastDV
          wrote on last edited by
          #4

          Does your myIODeviceThing object has a parent? If it has, I think you cannot move it to another thread.

          "[QObject Class Reference - moveToThread]":http://qt-project.org/doc/qt-4.8/qobject.html#moveToThread

          (8) Just live your life blind like me (8)

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RogueWarrior
            wrote on last edited by
            #5

            Nope, no parent.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              BlastDV
              wrote on last edited by
              #6

              Mmm well there's not too much I can help you with then. Luckily, since we've been posting stuff here, this may be on the top of the forum, so more people can see it and post an answer.

              (8) Just live your life blind like me (8)

              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