Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    WaitForBytesWritten crashes

    General and Desktop
    2
    6
    1384
    Loading More Posts
    • 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
      RogueWarrior last edited by

      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 Reply Quote 0
      • B
        BlastDV last edited by

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

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

        1 Reply Last reply Reply Quote 0
        • R
          RogueWarrior last edited by

              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 Reply Quote 0
          • B
            BlastDV last edited by

            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 Reply Quote 0
            • R
              RogueWarrior last edited by

              Nope, no parent.

              1 Reply Last reply Reply Quote 0
              • B
                BlastDV last edited by

                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 Reply Quote 0
                • First post
                  Last post