当前位置: 首页>>代码示例>>C++>>正文


C++ QDataStream::setDevice方法代码示例

本文整理汇总了C++中QDataStream::setDevice方法的典型用法代码示例。如果您正苦于以下问题:C++ QDataStream::setDevice方法的具体用法?C++ QDataStream::setDevice怎么用?C++ QDataStream::setDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDataStream的用法示例。


在下文中一共展示了QDataStream::setDevice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: command

bool DummyCommandPlugin::command(QString command, QList<QString> params)
{
    QFile dst("DummyCommandPlugin.txt");
    QDataStream sout;
    if(command == "append")
    {
        if(!dst.open(QIODevice::WriteOnly|QIODevice::Append))
        {
            return false;
        }
    }
    else if(command == "overwrite")
    {
        if(!dst.open(QIODevice::WriteOnly|QIODevice::Truncate))
        {
            return false;
        }
    }

    sout.setDevice(&dst);

    for(int i=0; i < params.size(); i++)
    {
        QString line(params[i] + QString("\n"));
        sout << line;
    }
    for(int i=0; i<100; i++)
    {
        qDebug() << "Doing nothing: " << i << "%";
        QApplication::processEvents();
    }
    dst.close();
    return true;
}
开发者ID:sarace77,项目名称:dlt-viewer,代码行数:34,代码来源:dummycommandplugin.cpp

示例2: saveIndex

void MailFolder::saveIndex(IndexClass *index)
{
    // open file
    QFile dataFile(indexFileName);
    QDataStream stream;
    stream.setDevice(&dataFile);

    // check to see if this is the first index and if so save the index version
    switch ( indexCollection.count() ) {
    case 0:
        // remove the file if there are not mails
        dataFile.remove();
        break;
    case 1:
        dataFile.open(IO_WriteOnly);
        stream<<QString(AQ_VERSION);
        // save index
        stream<<(*index);
        // close file
        dataFile.close();
        break;
    default:
        dataFile.open(IO_Append|IO_WriteOnly);
        // save index
        stream<<(*index);
        // close file
        dataFile.close();
        break;
    }
}
开发者ID:Miguel-J,项目名称:eneboo-core,代码行数:30,代码来源:mailfolder.cpp

示例3: loadReplay

void cTelnet::loadReplay( QString & name )
{
    replayFile.setFileName( name );
    QString msg = "loading replay " + name;
    postMessage( msg );
    replayFile.open( QIODevice::ReadOnly );
    replayStream.setDevice( &replayFile );
    loadingReplay = true;
    mudlet::self()->replayStart();
    _loadReplay();
}
开发者ID:olostan,项目名称:mudlet,代码行数:11,代码来源:ctelnet.cpp

示例4: readData

/*数据读取函数*/
void ClientSocket::readData()
{
    QDataStream in;
    in.setDevice(this);
    in.setVersion(QDataStream::Qt_4_7);

    QVariant v;
    AllAnswers allAnswers;
    Student student;
    /*如果还没有块大小信息则尝试去读取*/
    if(_totalBytes == 0)
    {
        /*如果缓存区中可读数据的大小小于块大小信息的大小则返回*/
        if(this->bytesAvailable()<sizeof(qint32))
            return;
        /*写入块大小信息*/
        in >> _totalBytes;
    }
    /*如果缓存区可读信息的大小小于块大小则返回*/
    if(this->bytesAvailable()<_totalBytes)
        return;
    /*反之则说明完整的数据块已经到达缓存区,可以开始读取*/
    /*写入信息类型*/
    in >> _messageType;
    /*根据信息类型写入信息内容*/
    switch(_messageType)
    {
    case MSG_NEWCONNECT:
        in >> student;
        v.setValue(student);
        break;
    case MSG_LOGIN:
        in >> student;
        student.setSockDescriptor(this->socketDescriptor());
        v.setValue(student);
        break;
    case MSG_GETPAPER:
        in >> student;
        v.setValue(student);
        break;
    case MSG_ANSWER:
        in >> allAnswers;
        v.setValue(allAnswers);
        break;
    case MSG_ANSWERSINGLE:
        in >> allAnswers;
        v.setValue(allAnswers);
        break;
    }
    /*将块大小信息重置为0,准备接收下一个数据块*/
    _totalBytes = 0;
    /*发送信息到达信号*/
    emit this->messageArrive(this->socketDescriptor(),_messageType,v);
}
开发者ID:AlanForeverAi,项目名称:Exams,代码行数:55,代码来源:server.cpp

示例5: readcfg

bool huancun::readcfg(){
    qDebug()<<"huancun::readcfg";
    QFile file;
    QString cfg=dirpath+"/cfg";
    file.setFileName(cfg);
    if(file.open(QIODevice::ReadOnly))
    {
        QDataStream in;
        in.setDevice(&file);
        in>>all>>name>>goon>>playurl>>urls>>playrf>>U_A;
        return true;
    }
开发者ID:noahsai,项目名称:mlsplayer,代码行数:12,代码来源:huancun.cpp

示例6: DB_Charger

bool Titres::DB_Charger(void)
{
	QFile file(SAVENAME);
	QDataStream out;

	if ( file.open(QIODevice::ReadOnly) )
	{
		out.setDevice(&file);
		out >> T_List;

		file.close();
		return true;
	}
开发者ID:Max13,项目名称:MangaMania,代码行数:13,代码来源:titres.cpp

示例7: read

void SessionManager::read()
{
    QFile f(_sessionsPath);
    QDataStream in;
    QVariant tmp;
    Session *session(0);

    // Opening the saving file
    if (!f.open(QIODevice::ReadOnly))
        return;

    in.setDevice(&f);

    // Reading of all sessions
    while (!in.atEnd())
    {
        session = new Session();

        // Retrieving of the access token
        in >> tmp;

        session->setAccessToken(tmp.toString());
        tmp.clear();

        // Retrieving of the client token
        in >> tmp;

        session->setClientToken(tmp.toString());
        tmp.clear();

        // Retrieving of the player's uuid
        in >> tmp;

        session->setUuid(tmp.toString());
        tmp.clear();

        // Retrieving of the player's username
        in >> tmp;

        session->setName(tmp.toString());
        tmp.clear();

        // Retrieving of the player's legacy
        in >> tmp;

        session->setLegacy(tmp.toBool());
        tmp.clear();
    }

    f.close();
}
开发者ID:rigma,项目名称:EMPLauncher,代码行数:51,代码来源:sessionmanager.cpp

示例8: play

bool QPicture::play( QPainter *painter )
{
    if ( pictb.size() == 0 )			// nothing recorded
	return TRUE;

    pictb.open( IO_ReadOnly );			// open buffer device
    QDataStream s;
    s.setDevice( &pictb );			// attach data stream to buffer

    if ( !formatOk ) {				// first time we read it
	char mf_id[4];				// picture header tag
	s.readRawBytes( mf_id, 4 );		// read actual tag
	if ( memcmp(mf_id, mfhdr_tag, 4) != 0 ) { // wrong header id
#if defined(CHECK_RANGE)
	    qWarning( "QPicture::play: Incorrect header" );
#endif
	    pictb.close();
	    return FALSE;
	}

	int cs_start = sizeof(Q_UINT32);		// pos of checksum word
	int data_start = cs_start + sizeof(Q_UINT16);
	Q_UINT16 cs,ccs;
	QByteArray buf = pictb.buffer();	// pointer to data
	s >> cs;				// read checksum
	ccs = qChecksum( buf.data() + data_start, buf.size() - data_start );
	if ( ccs != cs ) {
#if defined(CHECK_STATE)
	    qWarning( "QPicture::play: Invalid checksum %x, %x expected",
		     ccs, cs );
#endif
	    pictb.close();
	    return FALSE;
	}

	Q_UINT16 major, minor;
	s >> major >> minor;			// read version number
	if ( major > mfhdr_maj ) {		// new, incompatible version
#if defined(CHECK_RANGE)
	    qWarning( "QPicture::play: Incompatible version %d.%d",
		     major, minor);
#endif
	    pictb.close();
	    return FALSE;
	}
	formatOk = TRUE;			// picture seems to be ok
	formatMajor = major;
	formatMinor = minor;
    } else {
开发者ID:kthxbyte,项目名称:QT2-Linaro,代码行数:49,代码来源:qpicture.cpp

示例9: savePaperSetRelationFile

//保存各试卷关系信息
int CardDoc::savePaperSetRelationFile(int courseIndex, QString fileName)
{
	QList<QString> setId;
	QList<int> dpi;
	QList<int> pageCount;
	QList<QString> pageId;
	QList<bool> isPositive;

	vector<PaperSet>::iterator iter = m_course.at(courseIndex).set.begin();

	for (; iter != m_course.at(courseIndex).set.end(); ++iter)
	{
		setId.push_back(iter->setId);
		dpi.push_back(iter->dpi);
		pageCount.push_back(iter->page.size());

		vector<PaperPage>::iterator iter2 = iter->page.begin();

		for (; iter2 != iter->page.end(); ++iter2)
		{
			pageId.push_back(iter2->pageId);
			isPositive.push_back(iter2->isPositive);
		}
	}

	QFile file(fileName);

	if (!file.open(QIODevice::WriteOnly))
	{
		return 0;
	}

	QDataStream data;
	data.setDevice(&file);
	data.setVersion(QDataStream::Qt_4_8);

	//输出试卷关系信息
	data << quint32(PAPERSET_MAGIC_NUM) << quint32(VERSION) 
		 << m_acType << m_course.at(courseIndex).courseName
		 << m_course.at(courseIndex).set.size() << setId << dpi
		 << pageCount << pageId << isPositive;

	if (file.isOpen())
	{
		file.close();
	}
	return 1;
}
开发者ID:billhhh,项目名称:whcode_organizer,代码行数:49,代码来源:CardDoc.cpp

示例10: DB_Sauver

bool Titres::DB_Sauver(void)
{
	QFile file(SAVENAME);
	QDataStream in;

	if ( file.open(QIODevice::WriteOnly) )
	{
		in.setDevice(&file);
		in << T_List;

		file.close();
		return true;
	}
	else
		return false;
}
开发者ID:Max13,项目名称:MangaMania,代码行数:16,代码来源:titres.cpp

示例11: ensureSerializesCorrectly

void ensureSerializesCorrectly(const QPicture &picture, QDataStream::Version version)
 {
    QDataStream stream;

    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly);
    stream.setDevice(&buffer);
    stream.setVersion(version);
    stream << picture;
    buffer.close();

    buffer.open(QIODevice::ReadOnly);
    QPicture readpicture;
    stream >> readpicture;
    QVERIFY2(memcmp(picture.data(), readpicture.data(), picture.size()) == 0,
        qPrintable(QString::fromLatin1("Picture data does not compare equal for QDataStream version %1").arg(version)));
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:17,代码来源:tst_qpicture.cpp

示例12: Login

bool PackageReader::Login()
{
    QDataStream socketStream;
    socketStream.setVersion(QDataStream::Qt_4_8);
    socketStream.setDevice(s);
    struct User *user;
    int nameLen,passwdLen;
    QString name,passwd;
    socketStream>>nameLen;
    if(nameLen<0||nameLen>MAX_STR_LEN)
    {
        socketStream<<FAULT;
        return 0;
    }
    name.resize(nameLen);
    socketStream>>name;
    socketStream>>passwdLen;
    if(passwdLen<0||passwdLen>MAX_STR_LEN)
    {
        socketStream<<FAULT;
        return 0;
    }
    passwd.resize(passwdLen);
    socketStream>>passwd;
    qDebug()<<"user name"<<name<<"passwd:"<<passwd;
    /*bala
     *bala
     *bala
     */
    user = new struct User;
    user->name=name;
    user->add=s->peerAddress();
    user->online=1;
    user->port=s->peerPort();
    qDebug()<<user->name;
    if(-1==l->Insert(user))
    {
        delete user;
        socketStream<<FAULT;
        return 0;
    }
    socketStream<<SUCCEED;
    return 1;

}
开发者ID:k568613637,项目名称:Game,代码行数:45,代码来源:packagereader.cpp

示例13: on_pushButton_clicked

void chmEditer::on_pushButton_clicked()
{
    //
    chmHeader hd;
    QString fileName = QFileDialog::getOpenFileName(this,
         tr("Открыть chm"), ".", tr("Chm Files (*.chm)"));
//    fileName = "D:\\ferz\\chm1\\TestPrj.chm";
    QFile f;
    f.setFileName(fileName);
    if (f.open(QIODevice::ReadOnly))
    {
        QDataStream stream;
        stream.setDevice(&f);
        stream.setByteOrder(QDataStream::LittleEndian);

        char *tmp1;
        tmp1 = new char[4];
        stream.readRawData(tmp1,4);
        hd.header = tmp1;
        delete tmp1;

        stream>> hd.version;
        stream>> hd.lenght;
        stream.skipRawData(4);
        stream>>hd.timestamp;
        stream>>hd.languageID;

        tmp1 = new char[10];
        stream.readRawData(tmp1,10);
        hd.GUID1 = tmp1;
        delete tmp1;
        tmp1 = new char[10];
        stream.readRawData(tmp1,10);
        hd.GUID2 = tmp1;
        delete tmp1;

        qDebug()<<hd.GUID1;
        ui->textEdit->append("<b>Заголовок</b>: "+hd.header);
        ui->textEdit->append("<b>Версия</b>: "+QString("%1").arg(hd.version));
        ui->textEdit->append("<b>полный размер заголовка</b> : "+QString("%1").arg(hd.lenght));
        ui->textEdit->append("<b>Язык</b> : "+QString("%1").arg(hd.languageID,0, 16));
    }
开发者ID:Alexandr-Galko,项目名称:chmfile,代码行数:42,代码来源:chmediter.cpp

示例14: save

void SessionManager::save()
{
    QFile f(_sessionsPath);
    QDataStream out;

    // Opening the saving file
    if (!f.open(QIODevice::WriteOnly))
        return;

    out.setDevice(&f);

    // Writing of all sessions
    for (auto key : _sessions.keys().toStdList())
    {
        out << QVariant(_sessions[key]->accessToken().toString()) << QVariant(_sessions[key]->clientToken().toString());
        out << QVariant(_sessions[key]->uuid().toString()) << QVariant(_sessions[key]->name()) << QVariant(_sessions[key]->legacy());
    }

    // Closing the file
    f.close();
}
开发者ID:rigma,项目名称:EMPLauncher,代码行数:21,代码来源:sessionmanager.cpp

示例15: play

bool QPicture::play( QPainter *painter )
{
    if ( d->pictb.size() == 0 )			// nothing recorded
	return TRUE;

    if ( !d->formatOk && !d->checkFormat() )
	return FALSE;

    d->pictb.open( IO_ReadOnly );		// open buffer device
    QDataStream s;
    s.setDevice( &d->pictb );			// attach data stream to buffer
    s.device()->at( 10 );			// go directly to the data
    s.setVersion( d->formatMajor == 4 ? 3 : d->formatMajor );

    Q_UINT8  c, clen;
    Q_UINT32 nrecords;
    s >> c >> clen;
    Q_ASSERT( c == PdcBegin );
    // bounding rect was introduced in ver 4. Read in checkFormat().
    if ( d->formatMajor >= 4 ) {
	Q_INT32 dummy;
	s >> dummy >> dummy >> dummy >> dummy;
    }
开发者ID:Miguel-J,项目名称:eneboo-core,代码行数:23,代码来源:qpicture.cpp


注:本文中的QDataStream::setDevice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。