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. QDataStream "stopped working"
Forum Update on Monday, May 27th 2025

QDataStream "stopped working"

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 479 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
    rackover
    wrote on last edited by
    #1

    Hello,

    I'm doing the following operation :

    char firstQuery[512] = "{'command':'ask_session','version':'1.0','user_agent':'faf-client'}";
    
     QByteArray *block;
        QDataStream *out = new QDataStream(block, QIODevice::ReadWrite);
        out->setVersion(QDataStream::Qt_5_10);
    
        uint length = (2*sizeof(firstQuery) + 4);
        qDebug() << length;
    
        out->writeBytes((const char*)firstQuery, length);
    

    The next step would be to send this block into a socket.
    But I have a problem : the last function call "writeBytes" causes the app to "Stop working" with no error messages.

    Am I doing something wrong ?

    VRoninV 1 Reply Last reply
    0
    • R rackover

      Hello,

      I'm doing the following operation :

      char firstQuery[512] = "{'command':'ask_session','version':'1.0','user_agent':'faf-client'}";
      
       QByteArray *block;
          QDataStream *out = new QDataStream(block, QIODevice::ReadWrite);
          out->setVersion(QDataStream::Qt_5_10);
      
          uint length = (2*sizeof(firstQuery) + 4);
          qDebug() << length;
      
          out->writeBytes((const char*)firstQuery, length);
      

      The next step would be to send this block into a socket.
      But I have a problem : the last function call "writeBytes" causes the app to "Stop working" with no error messages.

      Am I doing something wrong ?

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      @rackover said in QDataStream "stopped working":

      QByteArray *block;

      dangling pointer

      out->writeBytes((const char*)firstQuery, length);

      out of bounds ( length>=std::extent<decltype(firstQuery)>::value)


      const QByteArray firstQuery ("{'command':'ask_session','version':'1.0','user_agent':'faf-client'}");
      
       QByteArray block;
          QDataStream out (&block, QIODevice::ReadWrite);
          out.setVersion(QDataStream::Qt_5_10);
          out.write(firstQuery);
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      6

      • Login

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