本文整理汇总了C++中QDataStream::device方法的典型用法代码示例。如果您正苦于以下问题:C++ QDataStream::device方法的具体用法?C++ QDataStream::device怎么用?C++ QDataStream::device使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDataStream
的用法示例。
在下文中一共展示了QDataStream::device方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: waitForAvailableBytes
static bool waitForAvailableBytes(QDataStream &stream, quint32 count)
{
while (stream.device()->bytesAvailable() < count) {
if (!stream.device()->waitForReadyRead(SOCKET_DELAY_MS)) {
return false;
}
}
return true;
}
示例2:
static qint32 rle_decode(QDataStream & abr, char *buffer, qint32 height)
{
qint32 n;
char ptmp;
char ch;
int i, j, c;
short *cscanline_len;
char *data = buffer;
// read compressed size foreach scanline
cscanline_len = new short[ height ];
for (i = 0; i < height; i++) {
// short
abr >> cscanline_len[i];
}
// unpack each scanline data
for (i = 0; i < height; i++) {
for (j = 0; j < cscanline_len[i];) {
// char
if (!abr.device()->getChar(&ptmp)) {
break;
}
n = ptmp;
j++;
if (n >= 128) // force sign
n -= 256;
if (n < 0) { // copy the following char -n + 1 times
if (n == -128) // it's a nop
continue;
n = -n + 1;
// char
if (!abr.device()->getChar(&ch)) {
break;
}
j++;
for (c = 0; c < n; c++, data++) {
*data = ch;
}
}
else {
// read the following n + 1 chars (no compr)
for (c = 0; c < n + 1; c++, j++, data++) {
// char
if (!abr.device()->getChar(data)) {
break;
}
}
}
}
}
delete [] cscanline_len;
return 0;
}
示例3: writeSizeToCache
bool IconCacheCreator::writeSizeToCache(QDataStream &out, const QList<int> &sizes) {
for (int i = 0; i < sizes.size(); i++) {
//out << sizes.at(i);
DPRINT("size: %d", out.device()->size());
out.writeRawData((const char *)&(sizes.at(i)), sizeof(int));
DPRINT("size: %d", out.device()->size());
}
return true;
}
示例4: while
static qint32 find_sample_count_v6(QDataStream & abr, AbrInfo *abr_info)
{
qint64 origin;
qint32 sample_section_size;
qint32 sample_section_end;
qint32 samples = 0;
qint32 data_start;
qint32 brush_size;
qint32 brush_end;
if (!abr_supported_content(abr_info))
return 0;
origin = abr.device()->pos();
if (!abr_reach_8BIM_section(abr, "samp")) {
// reset to origin
abr.device()->seek(origin);
return 0;
}
// long
abr >> sample_section_size;
sample_section_end = sample_section_size + abr.device()->pos();
if(sample_section_end < 0 || sample_section_end > abr.device()->size())
return 0;
data_start = abr.device()->pos();
while ((!abr.atEnd()) && (abr.device()->pos() < sample_section_end)) {
// read long
abr >> brush_size;
brush_end = brush_size;
// complement to 4
while (brush_end % 4 != 0) brush_end++;
qint64 newPos = abr.device()->pos() + brush_end;
if(newPos > 0 && newPos < abr.device()->size()) {
abr.device()->seek(newPos);
}
else
return 0;
samples++;
}
// set stream to samples data
abr.device()->seek(data_start);
//dbgKrita <<"samples : "<< samples;
return samples;
}
示例5: readFromDataStream
void LYTTextBox::readFromDataStream(QDataStream &in) {
qint64 saveStartPos = in.device()->pos();
LYTPane::readFromDataStream(in);
// the lengths are stored in bytes (not characters) and count the
// zero terminator, and strings are UTF-16 (I think) so we need
// to take it off here
in >> (quint16&)bufferLength;
bufferLength >>= 1;
bufferLength--;
quint16 stringLength;
in >> (quint16&)stringLength;
stringLength >>= 1;
stringLength--;
// read the material and font names
quint16 materialNum, fontNum;
in >> (quint16&)materialNum;
in >> (quint16&)fontNum;
materialName = m_layout.materials.getNameOfIndex(materialNum);
fontName = m_layout.m_fontRefs.at(fontNum);
in >> (quint8&)alignment;
in >> (quint8&)alignmentOverride;
in.skipRawData(2); // padding
quint32 stringOffset;
in >> (quint32&)stringOffset;
ReadRGBA8Color(colour1, in);
ReadRGBA8Color(colour2, in);
in >> (float&)fontSizeX;
in >> (float&)fontSizeY;
in >> (float&)charSpace;
in >> (float&)lineSpace;
// read the textbox contents
// subtract 8 to account for BinaryBlockHeader or whatever it's called
in.device()->seek(saveStartPos + stringOffset - 8);
ushort *rawText = new ushort[stringLength];
for (int i = 0; i < stringLength; i++)
in >> (quint16&)rawText[i];
text.setUtf16(rawText, stringLength);
delete[] rawText;
}
示例6: saveHeader
void
KBuildServiceTypeFactory::save(QDataStream &str)
{
KSycocaFactory::save(str);
#if 0 // not needed since don't have any additional index anymore
int endOfFactoryData = str.device()->pos();
// Update header (pass #3)
saveHeader(str);
// Seek to end.
str.device()->seek(endOfFactoryData);
#endif
}
示例7: save
void KBuildMimeTypeFactory::save(QDataStream &str)
{
KSycocaFactory::save(str);
str << (qint32) 0;
const int endOfFactoryData = str.device()->pos();
// Update header (pass #3)
saveHeader(str);
// Seek to end.
str.device()->seek(endOfFactoryData);
}
示例8: ExeCommand
//************************************************************************************************
void tReportGuiGetListServerModels::ExeCommand(QDataStream &_in)
{
// QStringList list;
// int num=-1;
// _in >> num;
// for(int i=0; i<num;i++)
// {
// QString file="";
// _in >> file;
// list.push_back(file);
// }
// ((MainForm*)link)->LocalListFile(list);
// ((MainForm*)link)->ServerListModels(list);
_in.device()->seek(0);
_in.device()->seek(54);
QByteArray block;
block=_in.device()->readAll();
((MainForm*)link)->SaveServerModelFiles(block);
// ui->lwListModels->selectionModel()->setCurrentIndex(((MainForm*)link)->slm_server_list_models, QItemSelectionModel::ClearAndSelect);
//((MainForm*)link)->slm_server_list_models->createIndex(((MainForm*)link)->NumCelServModel, 0);
// QModelIndex MI=ui->lwListModels->currentIndex();
// int N=MI.row();
// if(N>0)
// {
// ((MainForm*)link)->OnServerModelClick(MI);
// }
/*
QModelIndex MI=ui->lwListModels->currentIndex();
int N=MI.row();
if(N>0)
{
OnServerModelClick(MI);
}
*/
}
示例9: writeString
void OutgoingMessage::writeString(QDataStream &stream, QString string)
{
QByteArray utf8_data = string.toUtf8();
qint32 byte_count = utf8_data.size();
stream << byte_count;
stream.device()->write(utf8_data);
}
示例10: sendAllMessages
void KGameProcessIO::sendAllMessages(QDataStream &stream,int msgid, quint32 receiver, quint32 sender, bool usermsg)
{
qCDebug(GAMES_PRIVATE_KGAME) << "==============> KGameProcessIO::sendMessage (usermsg="<<usermsg<<")";
// if (!player()) return ;
//if (!player()->isActive()) return ;
if (usermsg)
{
msgid+=KGameMessage::IdUser;
}
qCDebug(GAMES_PRIVATE_KGAME) << "=============* ProcessIO (" << msgid << "," << receiver << "," << sender << ") ===========";
QByteArray buffer;
QDataStream ostream(&buffer,QIODevice::WriteOnly);
QBuffer *device=(QBuffer *)stream.device();
QByteArray data=device->buffer();;
KGameMessage::createHeader(ostream,sender,receiver,msgid);
// ostream.writeRawBytes(data.data()+device->at(),data.size()-device->at());
ostream.writeRawData(data.data(),data.size());
qCDebug(GAMES_PRIVATE_KGAME) << " Adding user data from pos="<< device->pos() <<" amount=" << data.size() << "byte";
//if (d->mMessageClient) d->mMessageClient->sendBroadcast(buffer);
if (d->mProcessIO)
{
d->mProcessIO->send(buffer);
}
}
示例11: checkHeader
bool BinaryFormat::checkHeader(QDataStream &stream) const
{
Q_UINT32 magic, version;
stream >> magic >> version;
QFile *file = dynamic_cast< QFile * >(stream.device());
if(!file)
{
kdError() << i18n("Not a file?") << endl;
return false;
}
if(magic != 0x2e93e)
{
kdError() << i18n("File '%1' is not binary format.").arg(file->name()) << endl;
return false;
}
if(version != BINARY_FORMAT_VERSION)
{
kdError() << i18n("File '%1' is the wrong version.").arg(file->name()) << endl;
return false;
}
return true;
}
示例12: p_bool
QString AbrStructParser::p_bool(QDataStream &buf){
//# ord converts 1 byte number
char byte;
buf.device()->getChar(&byte);
if (byte) return QString("1");
else return QString("0");
}
示例13: stream
QByteArray IQSMPPOptionalParameter<QString>::encode() const
{
QByteArray result;
//Если не устанавливали значения для данной опции, то вернем пустой массив, т.к. данная опция
//не используется
if (!_valueSets)
return result;
if (tag() == IQSMPP::UndefinedOptionalParameter)
return result;
if (maxLength() == 0)
return result;
QDataStream stream (&result, QIODevice::WriteOnly);
stream << (quint16) tag();
stream << (quint16) 0;
//Запишим данные
//Если это строка
QByteArray stringBA = _value.toLatin1();
const char * stringShar = stringBA.constData();
int stringLength = stringBA.length();
stream.writeRawData(stringShar, stringLength);
if (_cOctetString)
stream << (quint8)0x00;
//Сохраним размер
stream.device()->seek(2);
stream << (quint16) result.size() - 4;
return result;
}
示例14: writeVector
void writeVector(QDataStream& out, char ch, QVector<T> vec) {
// Minimum number of bytes to consider compressing
const int ATTEMPT_COMPRESSION_THRESHOLD_BYTES = 2000;
out.device()->write(&ch, 1);
out << (int32_t)vec.length();
auto data { QByteArray::fromRawData((const char*)vec.constData(), vec.length() * sizeof(T)) };
if (data.size() >= ATTEMPT_COMPRESSION_THRESHOLD_BYTES) {
auto compressedDataWithLength { qCompress(data) };
// qCompress packs a length uint32 at the beginning of the buffer, but the FBX format
// does not expect it. This removes it.
auto compressedData = QByteArray::fromRawData(
compressedDataWithLength.constData() + sizeof(uint32_t), compressedDataWithLength.size() - sizeof(uint32_t));
if (compressedData.size() < data.size()) {
out << FBX_PROPERTY_COMPRESSED_FLAG;
out << (int32_t)compressedData.size();
out.writeRawData(compressedData.constData(), compressedData.size());
return;
}
}
out << FBX_PROPERTY_UNCOMPRESSED_FLAG;
out << (int32_t)0;
out.writeRawData(data.constData(), data.size());
}
示例15: sendAllData
//отправление данных по всем кораблям
void MyServer::sendAllData(){
//deleteShipButton->setEnabled(false);
QByteArray block;
QDataStream out (&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_5);
out << quint16(0) << logNumbersOfRemovedShips.size(); //количество удаленных кораблей
for(int k = 0; k < logNumbersOfRemovedShips.size(); k++){ //номер лога удаленного корабля
out << logNumbersOfRemovedShips.at(k); //
}
logNumbersOfRemovedShips.clear();
out << shipCounter; //количество существующих на сервере кораблей
//для всех кораблей
for(int i=0; i < shipCounter; i++){
generateData(shipList.at(i)); //генерируем новые данные
out << shipList.at(i)->id
<< shipList.at(i)->startX
<< shipList.at(i)->startY
<< shipList.at(i)->courseAngle
<< shipList.at(i)->speed
<< shipList.at(i)->viewAngle
<< shipList.at(i)->viewLength
<< shipList.at(i)->pathLength
<< shipList.at(i)->time;
QTextEdit *te = (QTextEdit*)txtStack->widget(i); //получение указателя на лог текущего корабля
te->append(QString("Id: %1").arg(shipList.at(i)->id+1));//вывод сгенерированной информации в лог
if(shipList.at(i)->isNew){
te->append(QString("Start X: %1\nStart Y: %2")
.arg(shipList.at(i)->startX)
.arg(shipList.at(i)->startY));
}
te->append(QString("Course angle: %1 deg\nSpeed: %2\nView angle: %3 deg\nViewLength: %4\nPath length: %5 m\nTime: %6 sec\n")
.arg(shipList.at(i)->courseAngle)
.arg(shipList.at(i)->speed).arg(shipList.at(i)->viewAngle)
.arg(shipList.at(i)->viewLength).arg(shipList.at(i)->pathLength).arg(shipList.at(i)->time/1000.0f));
shipList.at(i)->isNew=0;
}
out.device()->seek(0); //переход в начало блока
out<<quint16(block.size()-sizeof(quint16)); //размер блока данных
if(isClientConnected) socket->write(block); //посылка клиенту, если он подключен
block.clear(); //очистка используемого блока
if(!deleteShipButton->isEnabled()&& shipCounter>0) deleteShipButton->setEnabled(true);
}