Results 1 to 3 of 3

Thread: Qt QDataStream supports data types

  1. #1
    Join Date
    Dec 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Red face Qt QDataStream supports data types

    like the question,hope someone can give me the right answer.thanks~

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt QDataStream supports data types

    Quote Originally Posted by LoginFailed View Post
    like the question,hope someone can give me the right answer.thanks~
    If your question is what data types QDataStream supports by default.
    qint8
    bool
    quint8
    quint16
    qint16
    qint32
    quint64
    qint64
    quint32
    float
    double
    const char *
    And you can always use QDataStream for your customized data types too.

  3. #3
    Join Date
    Dec 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Qt QDataStream supports data types

    Quote Originally Posted by yogeshgokul View Post
    If your question is what data types QDataStream supports by default.

    And you can always use QDataStream for your customized data types too.
    thanks for your answer.But it seems that there are some problems of my description.What I want to achieve is something like data analysis.This is the data analysis of my test source.

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    QSize s(100 , 100);
    QString str = "hello world";
    QList<QGenericArgument> param;
    param<<Q_ARG(QSize , s)<<Q_ARG(QString , str);
    netWorkRemoteCall("netwrok" , "sendData" , param);
    }


    void MainWindow::netWorkRemoteCall(QString className, QString methodName, QList<QGenericArgument> param)
    {
    QByteArray data;
    QStringList typeNames;
    QDataStream stream(&data , QIODevice::WriteOnly);
    stream<<className<<methodName;
    for(int q = 0 ; q < param.size() ; q++)
    {
    typeNames<<param.at(q).name();
    }
    stream<<typeNames;
    for(int i = 0 ; i < param.size() ; i++)
    {
    //stream<<param.at(i).name();
    if(param.at(i).name() == "QString")
    {
    QString str = *(QString *)param.at(i).data();
    stream<<str;
    }
    else if(param.at(i).name() == "QSize")
    {
    QSize size = *(QSize*)param.at(i).data();
    stream<<size;
    }
    }
    qDebug()<<data.size();
    dataAnalysis(data);
    }

    void MainWindow::dataAnalysis(QByteArray data)
    {
    QByteArray datas = data;
    qDebug()<<datas.size();
    QDataStream stream(datas);
    QString className;
    QString methodName;
    QStringList typeNames;
    stream>>className>>methodName>>typeNames;
    //qDebug()<<className<<methodName<<" "<<className.size() //+methodName.size();
    for(int i = 0 ; i < typeNames.size() ; i++)
    {
    qDebug()<<typeNames.at(i);
    if(typeNames.at(i) == "QString")
    {
    QString s;
    stream>>s;
    qDebug()<<s;
    }
    else if(typeNames.at(i) == "QSize")
    {
    QSize s;
    stream>>s;
    qDebug()<<s;
    }
    }
    }

    and I want to parse is the data like QVector<QStringList> , QPoint , QHash,QMap.I don't konw whether QDataStram support them.......

Similar Threads

  1. QFile, QDataStream reading binary data
    By yren in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2009, 06:34
  2. conversion of binay data to qt types
    By rajeshs in forum Qt Programming
    Replies: 16
    Last Post: 4th January 2008, 12:26
  3. QVariant::toString and custom data types
    By Vladimir in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2007, 15:36
  4. avaiability of data from QDataStream
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 19th June 2006, 12:32
  5. Use QVariant with custon data types
    By mcosta in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 14:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.