本文整理汇总了C++中QDataStream::status方法的典型用法代码示例。如果您正苦于以下问题:C++ QDataStream::status方法的具体用法?C++ QDataStream::status怎么用?C++ QDataStream::status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDataStream
的用法示例。
在下文中一共展示了QDataStream::status方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onIpcData
void ScProcess::onIpcData()
{
mIpcData.append(mIpcSocket->readAll());
while (mIpcData.size()) {
QBuffer receivedData ( &mIpcData );
receivedData.open ( QIODevice::ReadOnly );
QDataStream in ( &receivedData );
in.setVersion ( QDataStream::Qt_4_6 );
QString selector, message;
in >> selector;
if ( in.status() != QDataStream::Ok )
return;
in >> message;
if ( in.status() != QDataStream::Ok )
return;
mIpcData.remove ( 0, receivedData.pos() );
onResponse(selector, message);
emit response(selector, message);
}
}
示例2: HandleFile
bool ImportBinary::HandleFile (const QString& filename)
{
QFile file (filename);
if (!file.open (QIODevice::ReadOnly))
{
QMessageBox::critical (this,
tr ("LeechCraft"),
tr ("Could not open file %1 for reading.")
.arg (filename));
return false;
}
QByteArray buffer = qUncompress (file.readAll ());
QDataStream stream (&buffer, QIODevice::ReadOnly);
int magic = 0;
stream >> magic;
if (magic != static_cast<int> (0xd34df00d))
{
QMessageBox::warning (this,
tr ("LeechCraft"),
tr ("Selected file %1 is not a valid "
"LeechCraft::Aggregator exchange file.")
.arg (filename));
return false;
}
int version = 0;
stream >> version;
if (version != 1)
{
QMessageBox::warning (this,
tr ("LeechCraft"),
tr ("Selected file %1 is a valid LeechCraft::Aggregator "
"exchange file, but its version %2 is unknown")
.arg (filename)
.arg (version));
}
QString title, owner, ownerEmail;
stream >> title >> owner >> ownerEmail;
while (stream.status () == QDataStream::Ok)
{
Channel_ptr channel (new Channel (-1, -1));
stream >> (*channel);
Channels_.push_back (channel);
QStringList strings (channel->Title_);
strings << QString::number (channel->Items_.size ());
QTreeWidgetItem *item =
new QTreeWidgetItem (Ui_.FeedsToImport_, strings);
item->setCheckState (0, Qt::Checked);
}
return true;
}
示例3: SerializeIn
inline void SerializeIn(QDataStream& s, Ranges::List< Ranges::Range<quint64>, ListTraits >& rhs)
{
quint64 nTotal, nRemaining;
quint64 nFragments;
s >> nTotal >> nRemaining >> nFragments;
{
Ranges::List< Ranges::Range<quint64>, ListTraits > oNewRange(nTotal);
rhs.swap(oNewRange);
}
for( ; nFragments--; )
{
const Ranges::Range<quint64>& fragment = SerializeIn(s);
if( fragment.end() > nTotal )
{
s.setStatus(QDataStream::ReadCorruptData);
break;
}
else
{
rhs.insert(rhs.end(), fragment);
}
}
if( s.status() == QDataStream::Ok && rhs.length_sum() != nRemaining )
{
s.setStatus(QDataStream::ReadCorruptData);
}
}
示例4: getId
/** Writes group fields to the stream. Returns true on success, false in case of error. */
bool PwGroupV3::writeToStream(QDataStream& stream) {
stream << FIELD_GROUP_ID;
PwStreamUtilsV3::writeInt32(stream, getId());
stream << FIELD_NAME;
PwStreamUtilsV3::writeString(stream, getName());
stream << FIELD_CREATION_TIME;
PwStreamUtilsV3::writeTimestamp(stream, getCreationTime());
stream << FIELD_LAST_MODIFIED_TIME;
PwStreamUtilsV3::writeTimestamp(stream, getLastModificationTime());
stream << FIELD_LAST_ACCESS_TIME;
PwStreamUtilsV3::writeTimestamp(stream, getLastAccessTime());
stream << FIELD_EXPIRATION_TIME;
PwStreamUtilsV3::writeTimestamp(stream, getExpiryTime());
stream << FIELD_ICON_ID;
PwStreamUtilsV3::writeInt32(stream, getIconId());
stream << FIELD_GROUP_LEVEL;
PwStreamUtilsV3::writeUInt16(stream, getLevel());
stream << FIELD_GROUP_FLAGS;
PwStreamUtilsV3::writeInt32(stream, getFlags());
stream << FIELD_END << (qint32)0;
return (stream.status() == QDataStream::Ok);
}
示例5: parseHostAndPort
static bool parseHostAndPort(QDataStream &stream, quint8 &type, QByteArray &host, quint16 &port)
{
// get host name
quint8 hostLength;
stream >> type;
stream >> hostLength;
if (stream.status() != QDataStream::Ok)
return false;
host.resize(hostLength);
if (stream.readRawData(host.data(), hostLength) != hostLength) {
qWarning("Invalid host length");
return false;
}
// get port
stream >> port;
return stream.status() == QDataStream::Ok;
}
示例6: checkStream
void checkStream( QDataStream &stream )
{
if ( stream.status() != QDataStream::Ok )
{
if ( cf != -1 )
{
Rast_unopen( cf );
G_fatal_error( "Cannot read data stream" );
}
}
}
示例7: ReadString
bool CNetMsgBaseBuffered::ReadString(QString& str,QDataStream& in)
{
quint16 nSize = str.size();
in >> nSize;if(in.status()!=QDataStream::Ok){Q_ASSERT(NULL); return false;}
if (nSize)
{
QByteArray data;
data.resize(nSize);
if (in.readRawData(data.data(), nSize)==nSize)
{
str = QString::fromUtf8 (data.constData(),(nSize-1));//null terminated string
return true;
}
Q_ASSERT(NULL);
return false;
}
else
{
str.clear();
}
return true;
}
示例8: readField
int RTBinaryMessage::readField(QDataStream &stream, Field &field, uint pos)
{
switch (field.type)
{
case Padding:
{
uint paddingSize = field.value.toUInt();
quint8 pad = 0;
uint read = 0;
while (read < paddingSize && stream.status() == QDataStream::Ok)
{
stream >> pad;
++read;
}
return read;
}
break;
case PadTo:
{
uint paddingSize = field.value.toUInt();
quint8 pad = 0;
uint read = pos;
while (read < paddingSize && stream.status() == QDataStream::Ok)
{
stream >> pad;
++read;
}
return read;
}
break;
case PadByField:
{
QString fieldLookup = field.value.toString();
uint paddingSize = fieldValueV(fieldLookup).toUInt();
quint8 pad = 0;
uint read = 0;
while (read < paddingSize && stream.status() == QDataStream::Ok)
{
stream >> pad;
++read;
}
return read;
}
break;
case PadToField:
{
QString fieldLookup = field.value.toString();
uint paddingSize = fieldValueV(fieldLookup).toUInt();
quint8 pad = 0;
uint read = pos;
while (read < paddingSize && stream.status() == QDataStream::Ok)
{
stream >> pad;
++read;
}
return read;
}
break;
case Int8:
{
qint8 val = 0;
stream >> val;
field.value = val;
return stream.status() == QDataStream::Ok ? 1 : 0;
}
break;
case Uint8:
{
quint8 val = 0;
stream >> val;
field.value = val;
return stream.status() == QDataStream::Ok ? 1 : 0;
}
break;
case Int16:
{
qint16 val = 0;
stream >> val;
field.value = val;
return stream.status() == QDataStream::Ok ? 2 : 0;
}
break;
case Uint16:
{
quint16 val = 0;
stream >> val;
field.value = val;
return stream.status() == QDataStream::Ok ? 2 : 0;
}
break;
case Int32:
{
qint32 val = 0;
stream >> val;
field.value = val;
return stream.status() == QDataStream::Ok ? 4 : 0;
//.........这里部分代码省略.........
示例9: deserializeNavigationHistory
static void deserializeNavigationHistory(QDataStream &input, int *currentIndex, ScopedVector<content::NavigationEntry> *entries, content::BrowserContext *browserContext)
{
int version;
input >> version;
if (version != kHistoryStreamVersion) {
// We do not try to decode previous history stream versions.
// Make sure that our history is cleared and mark the rest of the stream as invalid.
input.setStatus(QDataStream::ReadCorruptData);
*currentIndex = -1;
return;
}
int count;
input >> count >> *currentIndex;
int pageId = 0;
entries->reserve(count);
// Logic taken from SerializedNavigationEntry::ReadFromPickle and ToNavigationEntries.
for (int i = 0; i < count; ++i) {
QUrl virtualUrl, referrerUrl, originalRequestUrl;
QString title;
QByteArray pageState;
qint32 transitionType, referrerPolicy;
bool hasPostData, isOverridingUserAgent;
qint64 timestamp;
int httpStatusCode;
input >> virtualUrl;
input >> title;
input >> pageState;
input >> transitionType;
input >> hasPostData;
input >> referrerUrl;
input >> referrerPolicy;
input >> originalRequestUrl;
input >> isOverridingUserAgent;
input >> timestamp;
input >> httpStatusCode;
// If we couldn't unpack the entry successfully, abort everything.
if (input.status() != QDataStream::Ok) {
*currentIndex = -1;
for (content::NavigationEntry *entry : *entries)
delete entry;
entries->clear();
return;
}
scoped_ptr<content::NavigationEntry> entry = content::NavigationController::CreateNavigationEntry(
toGurl(virtualUrl),
content::Referrer(toGurl(referrerUrl), static_cast<blink::WebReferrerPolicy>(referrerPolicy)),
// Use a transition type of reload so that we don't incorrectly
// increase the typed count.
ui::PAGE_TRANSITION_RELOAD,
false,
// The extra headers are not sync'ed across sessions.
std::string(),
browserContext);
entry->SetTitle(toString16(title));
entry->SetPageState(content::PageState::CreateFromEncodedData(std::string(pageState.data(), pageState.size())));
entry->SetPageID(pageId++);
entry->SetHasPostData(hasPostData);
entry->SetOriginalRequestURL(toGurl(originalRequestUrl));
entry->SetIsOverridingUserAgent(isOverridingUserAgent);
entry->SetTimestamp(base::Time::FromInternalValue(timestamp));
entry->SetHttpStatusCode(httpStatusCode);
entries->push_back(entry.release());
}
}
示例10: adoptVisitCounts
bool WebCore::HistoryItem::restoreState(QDataStream& in, int version)
{
// we only support version 1 for now
if (version != 1)
return false;
WebCore::String url;
WebCore::String title;
WebCore::String altTitle;
WebCore::String orginalUrl;
WebCore::String referrer;
WebCore::String target;
WebCore::String parrent;
double lastVisitedTime;
bool validUserData;
WebCore::String parent;
bool lastVisitWasHTTPNonGet;
bool lastVisitWasFailure;
bool isTargetItem;
int visitCount;
WTF::Vector<WebCore::String> documentState;
WebCore::IntPoint scrollPoint;
WTF::Vector<int> weeklyVisitCounts;
WTF::Vector<int> dailyVisitCounts;
// bool loadFormdata;
// WebCore::String formContentType;
// WTF::Vector<char> formData;
in >> url >> title >> altTitle >> lastVisitedTime >> orginalUrl >> referrer >> target >> parent;
in >> lastVisitWasHTTPNonGet >> lastVisitWasFailure >> isTargetItem >> visitCount >> documentState;
in >> scrollPoint >> dailyVisitCounts >> weeklyVisitCounts;
/*in >> loadFormdata;
if (loadFormdata) {
in >> formContentType >> formData;
// direct assigned (!)
m_formContentType = formContentType;
m_formData = FormData::create(CString(formData));
}*/
// use setters
adoptVisitCounts(dailyVisitCounts, weeklyVisitCounts);
setScrollPoint(scrollPoint);
setDocumentState(documentState);
setVisitCount(visitCount);
setIsTargetItem(isTargetItem);
setLastVisitWasFailure(lastVisitWasFailure);
setLastVisitWasHTTPNonGet(lastVisitWasHTTPNonGet);
setParent(parent);
setTarget(target);
setReferrer(referrer);
setOriginalURLString(orginalUrl);
setURLString(url);
setLastVisitedTime(lastVisitedTime);
setTitle(title);
setAlternateTitle(altTitle);
// at the end load userData
in >> validUserData;
if (validUserData) {
QVariant tmp;
in >> tmp;
setUserData(tmp);
}
return in.status() == QDataStream::Ok;
}
示例11: restoreState
bool QToolBarAreaLayout::restoreState(QDataStream &stream, const QList<QToolBar*> &_toolBars, uchar tmarker, bool testing)
{
QList<QToolBar*> toolBars = _toolBars;
int lines;
stream >> lines;
for (int j = 0; j < lines; ++j) {
int pos;
stream >> pos;
if (pos < 0 || pos >= QInternal::DockCount)
return false;
int cnt;
stream >> cnt;
QToolBarAreaLayoutInfo &dock = docks[pos];
const bool applyingLayout = !testing;
QToolBarAreaLayoutLine line(dock.o);
for (int k = 0; k < cnt; ++k) {
QToolBarAreaLayoutItem item;
QString objectName;
stream >> objectName;
uchar shown;
stream >> shown;
item.pos = getInt(stream);
item.size = getInt(stream);
/*
4.3.0 added floating toolbars, but failed to add the ability to restore them.
We need to store there geometry (four ints). We cannot change the format in a
patch release (4.3.1) by adding ToolBarStateMarkerEx2 to signal extra data. So
for now we'll pack it in the two legacy ints we no longer used in Qt4.3.0.
In 4.4, we should add ToolBarStateMarkerEx2 and fix this properly.
*/
QRect rect;
bool floating = false;
uint geom0, geom1;
geom0 = getInt(stream);
if (tmarker == ToolBarStateMarkerEx) {
geom1 = getInt(stream);
rect = unpackRect(geom0, geom1, &floating);
}
QToolBar *toolBar = 0;
for (int x = 0; x < toolBars.count(); ++x) {
if (toolBars.at(x)->objectName() == objectName) {
toolBar = toolBars.takeAt(x);
break;
}
}
if (toolBar == 0) {
continue;
}
if (applyingLayout) {
item.widgetItem = new QWidgetItemV2(toolBar);
toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o);
toolBar->setVisible(shown & 1);
toolBar->d_func()->setWindowState(floating, true, rect);
item.preferredSize = item.size;
line.toolBarItems.append(item);
}
}
if (applyingLayout) {
dock.lines.append(line);
}
}
return stream.status() == QDataStream::Ok;
}
示例12: on_actionView_PLY_File_triggered
//---------------------------------------------------------------------
// TODO factor code out of here and into its own class for loading and
// saving PLY files (additional code in stereo/multiviewstereo.cpp)
//
void MainWindow::on_actionView_PLY_File_triggered() {
QString initialDir = userSettings.contains("InitialPLYDir")
? userSettings.value("InitialPLYDir").toString()
: QDir::homePath();
// TODO sheets would be nice for Mac users :)
QString fname = QFileDialog::getOpenFileName(this,
tr("Open File"),
initialDir,
"PLY Files (*.ply)");
if(!fname.isNull()) {
QFile file(fname);
if(file.open(QFile::ReadOnly)) {
userSettings.setValue("InitialPLYDir", QDir(fname).absolutePath());
QTextStream textStream(&file);
// For now we'll ignore the header and assume a certain format
QString line;
bool hasNormal = false;
bool hasColor = false;
bool isBinary = false;
unsigned int numVertices = 0;
unsigned int numFaces = 0;
static QRegExp typeTest("n[xyz]");
static QRegExp normalTest("n[xyz]");
static QRegExp colorTest("diffuse_(red|blue|green)");
static QRegExp elementTest("element (vertex|face) (\\d+)");
while((line = textStream.readLine().trimmed()) != "end_header") {
if(line.startsWith("property")) {
if( line.contains(normalTest) )
hasNormal = true;
if( line.contains(colorTest) )
hasColor = true;
} else if(elementTest.indexIn(line) != -1) {
if(elementTest.cap(1) == "face")
numFaces = elementTest.cap(2).toUInt();
else if(elementTest.cap(1) == "vertex")
numVertices = elementTest.cap(2).toUInt();
} else if(line.startsWith("format")) {
isBinary = line.contains("binary");
}
}
QDataStream dataStream;
if(isBinary) {
qint64 pos = textStream.pos();
file.close();
file.open(QFile::ReadOnly);
dataStream.setDevice(&file);
dataStream.skipRawData(pos);
}
//
// Read in the verticies
//
GLfloat d[9] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
std::vector<GLfloat> vertices(numVertices * 9);
std::vector<GLfloat>::iterator vertexIter = vertices.begin();
if(isBinary) {
uint len = 12 + (hasNormal ? 12 : 0) + (hasColor ? 3 : 0);
// TODO more efficient to read in larger chunk of data
for(unsigned int vertex = 0; vertex < numVertices && !textStream.atEnd(); ++vertex) {
dataStream.readRawData(reinterpret_cast<char *>(d), len);
if(!hasNormal)
d[3] = d[4] = d[5] = 0;
if(!hasColor)
d[6] = d[7] = d[8] = 1;
if(dataStream.status() != QDataStream::ReadPastEnd)
vertexIter = std::copy(d, d + 9, vertexIter);
}
} else {
for(unsigned int vertex = 0; vertex < numVertices && !textStream.atEnd(); ++vertex) {
textStream >> d[0] >> d[1] >> d[2];
if(hasNormal)
textStream >> d[3] >> d[4] >> d[5];
else
d[3] = d[4] = d[5] = 0.0f;
if(hasColor) {
textStream >> d[6] >> d[7] >> d[8];
d[6] /= 255.0;
d[7] /= 255.0;
d[8] /= 255.0;
} else {
d[6] = d[7] = d[8] = 0.5f;
//d[6] = qrand() / (1.0*RAND_MAX);
//d[7] = qrand() / (1.0*RAND_MAX);
//.........这里部分代码省略.........