QDataStream "stopped working"



  • 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 ?



  • @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);
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.