Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QDataStream only accept Qt data types?



  • when i use Drag & Drop
    QByteArray itemData = event->mimeData()->data("xxx");
    QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    QString xxx;
    dataStream << xxx;

    can i pass other data type such as std::sting to dataStream, or even my own string type?

    thank you



  • Hello,

    You have to write your own implemenation of QDataStream operators (<<,>>) for your String Class e.g. MyString

    QDataStream &operator<<(QDataStream &out, const MyString &string)
    {......}

    QDataStream &operator>>(QDataStream &in, MyString &string)
    {......}


Log in to reply