本文整理汇总了C++中QByteArray::setRawData方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::setRawData方法的具体用法?C++ QByteArray::setRawData怎么用?C++ QByteArray::setRawData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::setRawData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_setFromRawData
void test_setFromRawData()
{
char rawData[] = "hello world!";
QByteArray ba;
QByteArray::DataPtr oldDataPtr = ba.data_ptr();
ba.setRawData(rawData, 5);
QVERIFY(oldDataPtr != ba.data_ptr());
oldDataPtr = ba.data_ptr();
ba.setRawData(rawData + 6, 5);
// Start using QByteArray::setRawData directly if the following QVERIFY fails.
// This would mean that the QByteArray::setRawData behavior has been changed to the
// desired one where switching from one raw data to another does not cause a
// QByteArray data block reallocation. Qt5 maybe?
QVERIFY(oldDataPtr != ba.data_ptr());
// Go ahead and do tests on our replacement setFromRawData.
ba = QByteArray();
oldDataPtr = ba.data_ptr();
QVERIFY(ba.data_ptr()->ref > 1); // Should be the multi-referenced shared null.
Pillow::ByteArrayHelpers::setFromRawData(ba, rawData, 0, 5);
QVERIFY(ba.data_ptr() != oldDataPtr);
QVERIFY(ba.data_ptr()->ref == 1);
QVERIFY(rawData[5] != '\0');
QCOMPARE(ba, QByteArray("hello"));
// Calling out setFromRawData on a string that is already detached should not reallocate the
// QByteArray data block, as opposed to QByteArray::setRawData.
oldDataPtr = ba.data_ptr();
Pillow::ByteArrayHelpers::setFromRawData(ba, rawData, 6, 5);
QVERIFY(ba.data_ptr() == oldDataPtr);
QVERIFY(ba.data_ptr()->ref == 1);
QVERIFY(rawData[11] != '\0');
QCOMPARE(ba, QByteArray("world"));
}
示例2: encode
QByteArray CryptData::encode(QString& txt, QString password)
{
if (lib_init == 0) {
return password.toUtf8();
}
DATA_BLOB DataIn;
QByteArray passwordArray{password.toUtf8()};
DataIn.pbData = (BYTE*)passwordArray.data();
DataIn.cbData = passwordArray.size() + 1;
DATA_BLOB Entropy;
QByteArray txtArray{txt.toUtf8()};
Entropy.pbData = (BYTE*)txtArray.data();
Entropy.cbData = txtArray.size() + 1;
DATA_BLOB DataOut;
QByteArray res;
BOOL r = pCryptProtectData(&DataIn, NULL, &Entropy, NULL, NULL, 0, &DataOut);
if (r == false) {
return res;
}
QByteArray data;
data.setRawData((const char*)DataOut.pbData, DataOut.cbData);
res.clear();
res.append("xxxx");
res.append(data.toBase64());
LocalFree(DataOut.pbData);
return res;
}
示例3: createAnimation
void ClsIqrGUI::createAnimation() {
QFrame *qframeSpace = new QFrame(qtoolbarToolbar);
qtoolbarToolbar->setStretchableWidget ( qframeSpace );
QFrame *qframeAnimation = new QFrame(qtoolbarToolbar);
QPalette palette;
palette.setColor(qframeAnimation->backgroundRole(), QColor(255,0,0));
qframeAnimation->setPalette(palette);
qframeAnimation->setFixedWidth(30);
qlblStatus = new QLabel(qframeAnimation, "animation");
#ifdef USE_MEMARRAY_LOGO
QByteArray qbaMoview;
qbaMoview.setRawData( movie_data, sizeof(movie_data) );
qlblStatus->setMovie(QMovie(qbaMoview));
#else
QString filename = "/usr/lib/iqr/iqr-logo.gif";
if(QFile::exists(filename)){
qlblStatus->setMovie(QMovie(filename));
}
#endif
if(qlblStatus->movie()!=NULL){
qlblStatus->movie()->pause();
qlblStatus->movie()->step();
}
}
示例4: sendDisplayData
void DisplayRenderer::sendDisplayData(QImage im1, QImage im2)
{
qDebug() << "sending data for displays";
PC2TB_PACKET outPacket;
// pack tha packet:
outPacket.magicNumber1 = MAGIC_NUMBER1;
outPacket.magicNumber2 = MAGIC_NUMBER2;
outPacket.packetVersion = PACKET_VERSION;
QTime midnight(0,0);
int time_ms = midnight.msecsTo(MainWindow::app()->getTimeBaseTime());
uint32_t time_100us = 10*time_ms;
outPacket.pcTime_100us = time_100us;
// ALGE text
memcpy(outPacket.algeText, algeText().toAscii().data(), ALGE_TEXT_LEN);
genMatrixData(im1, 1, outPacket.matrixData1);
genMatrixData(im2, 2, outPacket.matrixData2);
outPacket.matrixDataValid=1;
outPacket.cmdReceiver=COMMAND_INVALID_RECEIVER;
outPacket.command=COMMAND_INVALID_CMD;
outPacket.crc = CRC8_run((uint8_t*)(&outPacket), (uint16_t)(sizeof(PC2TB_PACKET)-1));
QByteArray datagram;
datagram.setRawData((char*)(&outPacket), sizeof(PC2TB_PACKET));
emit sendDatagram(datagram);
}
示例5:
QString datastream_control::m4_getpkt() {
m4_lock.lock();
QByteArray t;
t.setRawData((char *)construct_mode4 +3,12);
QString out = t.toHex();
out.toUpper();
m4_lock.unlock();
return out;
}
示例6: get
void kio_afpProtocol::get(const KURL& url )
{
kdDebug(7101) << "\n\nget " << url.prettyURL() << endl;
struct afp_url afp_url;
int ret;
unsigned int fileid;
unsigned long long total=0;
QString resumeOffset = metaData("resume");
// bool ok;
// struct stat stat;
// KIO::fileoffset_t offset = resumeOffset.toLongLong(&ok);
QString kafpurl = url.url(0,0);
afp_default_url(&afp_url);
afp_parse_url(&afp_url,kafpurl,0);
if (attachvolume(&afp_url)==false) {
kdDebug(7101) << "could not attach for get of " << url.prettyURL() << endl;
finished();
return;
}
ret=afp_sl_open(NULL,NULL,&afp_url, &fileid,0);
#if 0
char buffer[GET_DATA_SIZE];
QByteArray array;
while (eof==0) {
ret = afp_sl_read(&connection,&volid,fileid,0,
offset, GET_DATA_SIZE,&received,&eof,buffer);
array.setRawData(buffer,received);
data(array);
array.resetRawData(buffer,received);
total+=received;
offset=total;
}
infoMessage( i18n( "Retrieving %1 from %2...")
.arg(KIO::convertSize(retreived)) .arg(afp_url.servername));
#endif
totalSize(total);
ret=afp_sl_close(&volumeid,fileid);
}
示例7: fetch
bool NoSqlDatabase::fetch(const QString &key, QByteArray &data)
{
qDebug() << "Fetching data" << key;
::std::string value;
if( ! m_db->Get(leveldb::ReadOptions(), key.toStdString(), &value).ok() ) {
qDebug() << "Data not found" << key;
return false;
}
data.setRawData(value.c_str(), value.size());
data.detach();
return true;
}
示例8: loadFromData
bool QPixmap::loadFromData( const uchar *buf, uint len, const char *format,
int conversion_flags )
{
QByteArray a;
a.setRawData( (char *)buf, len );
QBuffer b( a );
b.open( IO_ReadOnly );
QImageIO io( &b, format );
bool result = io.read();
b.close();
a.resetRawData( (char *)buf, len );
if ( result ) {
detach();
result = convertFromImage( io.image(), conversion_flags );
}
return result;
}
示例9: sh
Id::Id(const char *name)
{
static uint firstUnusedId = 1;
static QByteArray temp;
temp.setRawData(name, qstrlen(name)); // avoid copying data
StringHash sh(temp);
int id = idFromString.value(sh, 0);
if (id == 0) {
id = firstUnusedId++;
sh.string = QByteArray(temp.constData(), temp.length()); // copy
idFromString.insert(sh, id);
stringFromId.insert(id, sh);
}
mId = id;
}
示例10: coverFromXiphComment
bool CoverUtils::coverFromXiphComment(TagLib::Ogg::XiphComment *xiphComment, Album *album) {
if (!xiphComment) return false;
const TagLib::StringList &stringList = xiphComment->fieldListMap()["COVERART"];
if (stringList.isEmpty()) return false;
TagLib::ByteVector byteVector = stringList.front().data(TagLib::String::Latin1);
QByteArray encodedData;
encodedData.setRawData(byteVector.data(), byteVector.size());
QByteArray data = QByteArray::fromBase64(encodedData);
QImage image;
image.loadFromData(data);
if (!isAcceptableImage(image)) return false;
qDebug() << "Cover from Xiph!";
return saveImage(image, album);
}
示例11: OnMReceive
void Client::OnMReceive() {
const auto byteCount = receiveSocket_->bytesAvailable();
//new a buffer
char buf[byteCount];
const auto readCount = receiveSocket_->readDatagram(buf, byteCount );
QByteArray ba;
ba.setRawData( buf, readCount );
QDataStream so(&ba, QIODevice::ReadOnly);
int width;
int height;
int top;
QPixmap newMap;
so >> width >> height >> top >> newMap;
//update the contents
pcv_->redrawPixmap( width, height, top, newMap );
}
示例12: sizeof
void DialogTimeStampGenerator2::on_pushButton_clicked()
{
static TB2PC_PACKET p;
static ALIVE_PACKET ap;
p.magicNumber1 = MAGIC_NUMBER1;
p.magicNumber2 = MAGIC_NUMBER2;
p.packetVersion = ui->lineEdit_packetVersion->text().toInt();
p.batteryVoltageTB = ui->lineEdit_batteryVoltageTB->text().toInt();
p.triggerStationID = ui->comboBox_triggerStationID->itemData(ui->comboBox_triggerStationID->currentIndex()).toInt();
p.binRssiTS = ui->lineEdit_binRssiTS->text().toInt();
QTime t0(0,0,0);
ap.triggerTimeBB = t0.msecsTo(ui->timeEdit_triggerTimeBB->time())*10;
ap.triggerTimeTS_L = t0.msecsTo(ui->timeEdit_triggerTimeTS_L->time())*10;
ap.triggerTimeTS_R = t0.msecsTo(ui->timeEdit_triggerTimeTS_R->time())*10;
ap.batteryVoltageTS = ui->lineEdit_batteryVoltageTS->text().toInt();
ap.batteryVoltageBB = ui->lineEdit_batteryVoltageBB->text().toInt();
ap.boatBoxID = ui->comboBox_boatBoxID->itemData(ui->comboBox_boatBoxID->currentIndex()).toInt();
ap.binRssiBB = ui->lineEdit_binRssiBB->text().toInt();
ap.stationTriggeredAt = ui->comboBox_stationTriggeredAt->itemData(ui->comboBox_stationTriggeredAt->currentIndex()).toInt();
p.tsPacket = ap;
p.baseTime_100us = t0.msecsTo(ui->timeEdit_baseTime->time())*10;
p.crc = CRC8_run((uint8_t*)(&p), sizeof(p)-1);
//printPacket(p);
QByteArray datagram;
datagram.setRawData((char*)(&p), sizeof(p));
QUdpSocket* udpSocket = new QUdpSocket(this);
udpSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, UDP_LISTEN_PORT);
}
示例13: run
void QWebcamServer::run()
{
qDebug() << tr("Webcam Server Thread started");
// >>>>> Frame compression parameters
vector<int> params;
params.push_back(CV_IMWRITE_JPEG_QUALITY);
params.push_back(85);
// <<<<< Frame compression parameters
quint8 frameCount = 0;
// >>>>> Thread Initialization
mUdpSocketSender = new QUdpSocket();
// Multicast on the subnet
mUdpSocketSender->setSocketOption( QAbstractSocket::MulticastTtlOption, 1 );
mUdpSocketReceiver = new QUdpSocket();
mUdpSocketReceiver->bind( mListenPort, QUdpSocket::ShareAddress );
connect( mUdpSocketReceiver, SIGNAL(readyRead()),
this, SLOT(onReadyRead() ) );
mStopped = false;
// <<<<< Thread Initialization
cv::Mat frame;
vector<uchar> compressed;
setPriority( QThread::TimeCriticalPriority );
// >>>>> Thread Loop
forever
{
// Waiting between loops according to FPS
double sleepMsec = 1000.0/((double)mFps);
QTime chrono;
chrono.start();
mStopMutex.lock();
{
if( mStopped )
{
mStopMutex.unlock();
break;
}
}
mStopMutex.unlock();
if( !mWebcamConnected )
mWebcamConnected = connectWebcam();
if(mWebcamConnected)
mCap >> frame;
else
{
int h = mDefImage.height();
int w = mDefImage.width();
cv::Mat img( h, w, CV_8UC3, mDefImage.bits() );
frame = img.clone();
}
frameCount++;
//qDebug() << tr( "Frame %1").arg( frameCount );
#ifdef WIN32
if( !frame.empty() )
{
cv::imshow( "Frame", frame );
}
#endif
//QTime chrono_elab;
//chrono_elab.start();
// JPG Compression in memory
if( !frame.empty() )
{
cv::imencode( ".jpg", frame, compressed, params );
// >>>>> UDP Sending
QByteArray fullDatagram;
fullDatagram.setRawData( (char*)compressed.data(), compressed.size() );
sendFragmentedData( fullDatagram, frameCount );
// <<<<< UDP Sending
}
//qDebug() << tr("Elaboration time: %1 msec").arg(chrono_elab.elapsed());
QCoreApplication::processEvents( QEventLoop::AllEvents, 1 );
int elapsed = chrono.elapsed();
//qDebug() << tr("Elapsed: %1 msec").arg(elapsed);
int sleep = sleepMsec - elapsed;
// >>>>> FPS auto-tuning
// Note FPS are tuned such to give to client at 10msec between
//.........这里部分代码省略.........
示例14: getContactData
virtual void getContactData(QByteArray& contactCardData) const override
{
contactCardData.setRawData (Data.body.data(), Data.body.size());
}
示例15: fromDir
//----------------------------------------------------------------
QVariant AbifReader::fromDir(const AbifDir &dir)
{
// Try to unserialize all data ! Not sure if all is working
// Check specification from http://www6.appliedbiosystems.com/support/software_community/ABIF_File_Format.pdf
//debugDir(dir);
QByteArray part;
if (dir.dataSize<=4){
int val = dir.dataOffset;
val = __bswap_32(val);
char * data = (char*)&val;
part.setRawData(data,dir.dataSize);
}
else {
mDevice->seek(dir.dataOffset);
part = mDevice->read(dir.dataSize);
}
QDataStream stream(part);
stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
stream.setByteOrder(QDataStream::BigEndian);
//-----------------------------------------------
if (Type(dir.elementType) == CString ) // 19
{
part.chop(1);
return QString(part);
}
//-----------------------------------------------
if (Type(dir.elementType) == PString ) // 18
{
part.remove(0,1);
return QString(part);
}
//-----------------------------------------------
if (Type(dir.elementType) == Word ) // 3
return QString(part);
//-----------------------------------------------
if (Type(dir.elementType) == Char ) // 2
return QString(part);
//-----------------------------------------------
if (Type(dir.elementType) == Short ) // 4
{
QVariantList list;
qint16 v;
if (dir.name == "Scal")
{
qDebug()<<dir.elementsize;
}
while (!stream.atEnd())
{
stream >> v;
list.append(v);
}
return reduce(list);
}