PDA

View Full Version : Qt QDataStream supports data types



LoginFailed
30th December 2009, 07:55
like the question,hope someone can give me the right answer.thanks~

yogeshgokul
30th December 2009, 08:04
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.

LoginFailed
30th December 2009, 08:41
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.......