本文整理汇总了C++中QByteArray::toStdString方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::toStdString方法的具体用法?C++ QByteArray::toStdString怎么用?C++ QByteArray::toStdString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::toStdString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void ConnectionThread::run()
{
if(stepByStep)
sendNextCommand = false;
else
sendNextCommand = true;
QSerialPort serial;
serial.setPortName(portName);
if (!serial.open(QIODevice::ReadWrite))
{
emit error(tr("Can't open %1, error code %2").arg(portName).arg(serial.error()));
return;
}
while (!quit) {
if(stepByStep)
{
while(!sendNextCommand);
mutex.lock();
sendNextCommand = false;
mutex.unlock();
}
// Envoi microcommande
serial.write(test->recupProchaineMicrocommande().c_str());
if(!serial.waitForBytesWritten(waitTimeout))
{
emit timeout(tr("Wait write microcommande timeout %1").arg(QTime::currentTime().toString()));
}
//Accusé de reception
if(serial.waitForReadyRead(waitTimeout))
{
QByteArray received = serial.readAll();
if(received.toStdString().compare(COMMANDE_RECEIVED) != 0)
{
emit error("Not wanted response");
}
}
else
{
emit timeout(tr("Wait read response timeout %1").arg(QTime::currentTime().toString()));
}
//Pret a recevoir prochaine commande
if(serial.waitForReadyRead(waitTimeout))
{
QByteArray received = serial.readAll();
if(received.toStdString().compare(READY_FOR_NEXT_COMMAND) != 0)
{
emit error("Not wanted response");
}
}
else
{
emit timeout(tr("Wait read response timeout %1").arg(QTime::currentTime().toString()));
}
}
}
示例2: slotReadyRead
void TcpClient::slotReadyRead()
{
while(m_pTcpSocket->bytesAvailable())
{
if (m_pTcpSocket->bytesAvailable() > headerMsgSize) {
QByteArray buffer = m_pTcpSocket->read(headerMsgSize);
QByteArray newarray;
for (int i = 0; i < buffer.size(); i++) {
if (buffer.at(i) == '\0')
continue;
newarray.append(buffer.at(i));
}
int msgSize = QString(newarray.toStdString().c_str()).toInt();
buffer.clear();
newarray.clear();
buffer = m_pTcpSocket->read(msgSize);
while(buffer.size() < msgSize - headerMsgSize)
{
m_pTcpSocket->waitForReadyRead(3000);
buffer.append(m_pTcpSocket->read(msgSize - buffer.size()));
}
for (int i = 0; i < buffer.size(); i++) {
newarray.append(buffer.at(i));
}
if (msgSize != (newarray.length() + headerMsgSize)) {
emit fileLoadingError("Данные были повреждены при скачивании. Попробуйте повторить процедуру сначала.");
emit startFileDownloading();
return;
}
QString fullMsg(newarray.toStdString().c_str());
if (fullMsg.contains(newfileMsg) && fullMsg.contains(newentryMsg)) {
processFileSaving(newarray);
} else {
processFileList(fullMsg);
}
} else {
emit fileLoadingError("Сервер не содержит запрашиваемых файлов. Обратитесь за помощью скачивания файлов к преподавателю.");
return;
}
}
}
示例3: getInfo
ffmpegFileInfo Ffmpeg::getInfo() {
QString ffmpegCachePath = getFfmpegCache().getQString();
QString tempPath = ffmpegCachePath + "//" + cleanPathSymbols() + ".txt";
if (QFile::exists(tempPath)) {
QFile infoText(tempPath);
infoText.open(QIODevice::ReadOnly);
QByteArray ba = infoText.readAll();
infoText.close();
QString text = QString::fromStdString(ba.toStdString());
m_lx = text.split(" ")[0].toInt();
m_ly = text.split(" ")[1].toInt();
m_frameRate = text.split(" ")[2].toDouble();
m_frameCount = text.split(" ")[3].toInt();
} else {
QFile infoText(tempPath);
getSize();
getFrameRate();
getFrameCount();
infoText.open(QIODevice::WriteOnly);
std::string infoToWrite =
std::to_string(m_lx) + " " + std::to_string(m_ly) + " " +
std::to_string(m_frameRate) + " " + std::to_string(m_frameCount);
int infoLength = infoToWrite.length();
infoText.write(infoToWrite.c_str(), infoLength);
infoText.close();
}
ffmpegFileInfo info;
info.m_lx = m_lx;
info.m_ly = m_ly;
info.m_frameRate = m_frameRate;
info.m_frameCount = m_frameCount;
return info;
}
示例4: request
// open by connecting and getting a basic list of folders available
bool
PolarFlow::open(QStringList &errors)
{
printd("PolarFlow::open\n");
// do we have a token
QString token = getSetting(GC_POLARFLOW_TOKEN, "").toString();
if (token == "") {
errors << "You must authorise with PolarFlow first";
return false;
}
// use the configed URL
QString url = QString("%1/rest/users/delegates/users")
.arg(getSetting(GC_POLARFLOW_URL, "https://whats.todaysplan.com.au").toString());
printd("URL used: %s\n", url.toStdString().c_str());
// request using the bearer token
QNetworkRequest request(url);
request.setRawHeader("Authorization", (QString("Bearer %1").arg(token)).toLatin1());
QNetworkReply *reply = nam->get(request);
// blocking request
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if (reply->error() != QNetworkReply::NoError) {
qDebug() << "error" << reply->errorString();
errors << tr("Network Problem reading PolarFlow data");
return false;
}
// did we get a good response ?
QByteArray r = reply->readAll();
printd("response: %s\n", r.toStdString().c_str());
QJsonParseError parseError;
QJsonDocument document = QJsonDocument::fromJson(r, &parseError);
// if path was returned all is good, lets set root
if (parseError.error == QJsonParseError::NoError) {
printd("NoError");
// we have a root
root_ = newCloudServiceEntry();
// path name
root_->name = "/";
root_->isDir = true;
root_->size = 0;
} else {
errors << tr("problem parsing PolarFlow data");
}
// ok so far ?
if (errors.count()) return false;
return true;
}
示例5: encryptAsymmetricly
QByteArray Encryptor::encryptAsymmetricly(QByteArray &publicKey, QByteArray &data)
{
Botan::DataSource_Memory key_pub(publicKey.toStdString());
auto publicRsaKey = Botan::X509::load_key(key_pub);
const uint DATA_SIZE = data.size();
Botan::byte msgtoencrypt[DATA_SIZE];
for (uint i = 0; i < DATA_SIZE; i++)
{
msgtoencrypt[i] = data[i];
}
Botan::PK_Encryptor_EME encryptor(*publicRsaKey, "EME1(SHA-256)");
Botan::AutoSeeded_RNG rng;
std::vector<Botan::byte> ciphertext = encryptor.encrypt(msgtoencrypt, DATA_SIZE, rng);
QByteArray keyCipherData;
keyCipherData.resize(ciphertext.size());
for ( uint i = 0; i < ciphertext.size(); i++ ) {
keyCipherData[i] = ciphertext.at(i);
}
return keyCipherData;
}
示例6: Serialize
std::string BuyoutManager::Serialize(const QMap<QString, Buyout> &buyouts) {
QJsonDocument doc;
QJsonObject root;
for (QString hash : buyouts.uniqueKeys()) {
Buyout buyout = buyouts.value(hash);
if (buyout.type != BUYOUT_TYPE_NO_PRICE && (buyout.currency == CURRENCY_NONE || buyout.type == BUYOUT_TYPE_NONE))
continue;
if (buyout.type >= BuyoutTypeAsTag.size() || buyout.currency >= CurrencyAsTag.size()) {
QLOG_WARN() << "Ignoring invalid buyout, type:" << buyout.type
<< "currency:" << buyout.currency;
continue;
}
QJsonObject value;
value.insert("value", buyout.value);
value.insert("set_by", buyout.set_by);
if (!buyout.last_update.isNull()){
value.insert("last_update", (int) buyout.last_update.toTime_t());
} else {
// If last_update is null, set as the actual time
value.insert("last_update", (int) QDateTime::currentDateTime().toTime_t());
}
value.insert("type", QString::fromStdString(BuyoutTypeAsTag[buyout.type]));
value.insert("currency", QString::fromStdString(CurrencyAsTag[buyout.currency]));
root.insert(hash, value);
}
doc.setObject(root);
QByteArray result = doc.toJson();
return result.toStdString();
}
示例7: decodeMsg
void elFlowPort::decodeMsg( const QByteArray& msg )
{
elFlowAnswer answer = _protocol.interpretAnswer( msg.toStdString() );
if( answer.type == elFlowAnswerType::elFlowError )
{
emit portError( "Invalid answer!" );
}
else if( answer.type == elFlowAnswerType::protocolError )
{
emit portError( "Protocol error!" );
}
else if( answer.type == elFlowAnswerType::elFlowStatus )
{
if( answer.text.find( "no error" ) == std::string::npos )
{
emit portError( QString::fromStdString( answer.text ) );
}
}
else if( answer.type == elFlowAnswerType::elFlowValue )
{
showParameter( answer.paramNum, answer.value, answer.text );
}
else
{
emit portError( "Warning: unhandled answer type!" );
}
}
示例8: on_finished
void MainWindow::on_finished(QNetworkReply* reply)
{
//qDebug("MainWindow::on_finished");
QByteArray data = reply->readAll();
std::string replyContent = data.toStdString();
qDebug("MainWindow::on_finished reply: %s", replyContent.c_str());
QJsonDocument doc = QJsonDocument::fromJson(data);
QJsonObject json = doc.object();
QString replyType = json["type"].toString();
qDebug("MainWindow::on_finished type = %s", replyType.toStdString().c_str());
if (replyType == "messageCount")
{
unsigned int currentMessagesCount = json["count"].toInt();
qDebug("MainWindow::on_finished count: %d", currentMessagesCount);
if (currentMessagesCount > m_messagesReceived)
{
m_getLastMessages(currentMessagesCount - m_messagesReceived);
}
}
else if (replyType == "getLastMessages")
{
qDebug("on_finished type: %d", json["messages"].type());
QJsonArray messages = json["messages"].toArray();
m_updateMessages(messages);
}
}
示例9: startRequest
void YunClient::startRequest(QByteArray url)
{
#ifndef QREQUEST
qDebug() << " request url : " << url;
std::string std_url = url.toStdString(); // "http://121.40.218.177:8080/ml/rs/mediaReleaseVersions/1/10/null/null/90001";
std::string readData;
CurlUpload *curl = new CurlUpload();
QString data = curl->getRequest(std_url, readData);
delete curl;
QJsonObject dataJson = getRequestData(QString(data));
QJsonArray listJson = setPagingInfo(dataJson);
setVersionList(listJson);
#else
QNetworkRequest request;
request.setUrl(QUrl(url));
manager = new QNetworkAccessManager(this);
//发送GET请求
reply = manager->get(request);
//连接请求结束信号
disconnect(reply);
connect(reply, &QNetworkReply::finished,
this, &YunClient::replyFinished);
连接响应时返回数据信号
connect(reply, &QNetworkReply::readyRead, this, &YunClient::readyRead);
请求更新进度
connect(reply, &QNetworkReply::downloadProgress,
this, &YunClient::updateDataReadProgress);
#endif
}
示例10: removeComa
void Core::removeComa(QFile &file){
QFile outfile(QString("/home/ethel/qwt-5.2/test-ethel/wireshark/resultats/report2.csv"));
if (!outfile.open(QIODevice::ReadWrite | QIODevice::Text))
{
qDebug() << "Unable to open file";
return;
}
if (!_reportFile.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Append))
{
qDebug() << "Unable to open file";
return;
}
_reportFile.seek(0);
while (!_reportFile.atEnd())
{
QByteArray line = _reportFile.readLine();
std::string s=line.toStdString();
std::replace( s.begin(), s.end(), '.', ',');
QTextStream stream(&outfile);
stream << QString::fromStdString(s);
}
file.close();
}
示例11: onEnter
void CascadeClassifierNavigationPlayer::onEnter()
{
if (m_classifier) {
return;
}
QFile f(":/assets/lbpcascade_animeface.xml");
if (!f.open(QIODevice::ReadOnly)) {
qWarning("Fail to load cascade classifier");
return;
}
QByteArray content = f.readAll();
cv::FileStorage cvFile(content.toStdString(), cv::FileStorage::READ | cv::FileStorage::MEMORY);
if (!cvFile.isOpened()) {
qWarning("Fail to load cascade classifier as cv::FileStorage");
return;
}
cv::CascadeClassifier *classifier = new cv::CascadeClassifier();
if (!classifier->read(cvFile.getFirstTopLevelNode())) {
qWarning("Fail to decode cascade classifer");
delete classifier;
return;
}
m_classifier = classifier;
}
示例12: handleSetCommand
void APIConnectionHandler::handleSetCommand(QLocalSocket *sock)
{
odb::database *db = DB::getDB();
Application connectedApp = getConnectedApp(sock);
sock->waitForReadyRead();
QByteArray username = sock->readLine().trimmed();
sock->waitForReadyRead();
string encryptedPassword = enc->encrypt(sock->readLine().trimmed().toStdString());
bool allow = startMessageViewerAndGetResult("an application want's to set a password, allow or reject?");
if ( allow )
{
vector<unsigned char> dbEncryptedPassword (encryptedPassword.begin(), encryptedPassword.end());
ApplicationPassword appPass(&connectedApp, username.toStdString(), dbEncryptedPassword);
int passwordId = db->persist(appPass);
sock->write(QVariant(passwordId).toByteArray());
} else {
sock->write("-1");
}
sock->write("\n");
sock->close();
}
示例13: xml
std::string TripletStore :: toRdf() const
{
QByteArray byteArray;
QXmlStreamWriter xml(&byteArray);
xml.setAutoFormatting(true);
xml.writeStartDocument();
xml.writeStartElement("rdf:RDF");
xml.writeAttribute("xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
xml.writeAttribute("xmlns:soft", "http://www.sintef.no/rdf#");
for (auto key: d->triplets.uniqueKeys()) {
auto i = d->triplets.find(key);
bool first = true;
while (i != d->triplets.cend() && i.key() == key) {
if (!i.value().first.startsWith("^")) {
if (first) {
xml.writeStartElement("rdf:Description");
xml.writeAttribute("xmlns:about", key);
first = !first;
}
xml.writeTextElement(i.value().first, i.value().second);
}
++i;
}
if (!first)
xml.writeEndElement();
}
xml.writeEndElement();
xml.writeEndDocument();
return byteArray.toStdString();
}
示例14: GetPosition
double Motor::GetPosition()
{
stringstream cmd;
QByteArray line;
cmd.str("");
cmd.clear();
if (!TX_LOCKOUT)
{
//qDebug() << "Get Position";
TALK_TO_MOTOR(cmd);
cmd << "?96" << CRLF;
line = SendCommand(cmd);
//qDebug() << line;
line.clear();
cmd.str("");
cmd.clear();
cmd << CRLF;
line = SendCommand(cmd);
if (!line.isEmpty())
{
if (line.at(0) == 'P')
{
//qDebug()<< "I'll have a P please Bob";
QByteArray tmp = line.mid(5); // chomp the first 5 characters to leave just the number
//qDebug() <<"Chomped first 5 chars " << tmp;
std::string position = tmp.toStdString();
int tpos = atoi (position.c_str());
//qDebug()<< "converted to longs" <<tpos;
double pos = (m_circumference * tpos) / 50000;
//qDebug()<<"converted to actual position" << pos;
STOP_TALKING_TO_MOTOR(cmd);
return pos;
}
else
{
STOP_TALKING_TO_MOTOR(cmd);
return -1;
}
}
else
{
STOP_TALKING_TO_MOTOR(cmd);
return -1;
}
}
else
{
STOP_TALKING_TO_MOTOR(cmd);
return -1;
}
}
示例15: spell
bool SpellCheck::spell(const QString word)
{
if(spellChecker == nullptr)
return true;
QByteArray w;
if(codec != nullptr)
w = codec->fromUnicode(word);
else
w = word.toLocal8Bit();
return spellChecker->spell(w.toStdString());
}