本文整理汇总了C++中QFile::putChar方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::putChar方法的具体用法?C++ QFile::putChar怎么用?C++ QFile::putChar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::putChar方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveNativeCSVFile
bool FrameFileIO::saveNativeCSVFile(QString filename, const QVector<CANFrame>* frames)
{
QFile *outFile = new QFile(filename);
int lineCounter = 0;
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
{
delete outFile;
return false;
}
outFile->write("Time Stamp,ID,Extended,Bus,LEN,D1,D2,D3,D4,D5,D6,D7,D8");
outFile->write("\n");
for (int c = 0; c < frames->count(); c++)
{
lineCounter++;
if (lineCounter > 100)
{
qApp->processEvents();
lineCounter = 0;
}
outFile->write(QString::number(frames->at(c).timestamp).toUtf8());
outFile->putChar(44);
outFile->write(QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8());
outFile->putChar(44);
if (frames->at(c).extended) outFile->write("true,");
else outFile->write("false,");
outFile->write(QString::number(frames->at(c).bus).toUtf8());
outFile->putChar(44);
outFile->write(QString::number(frames->at(c).len).toUtf8());
outFile->putChar(44);
for (int temp = 0; temp < 8; temp++)
{
if (temp < frames->at(c).len)
outFile->write(QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8());
else
outFile->write("00");
outFile->putChar(44);
}
outFile->write("\n");
}
outFile->close();
delete outFile;
return true;
}
示例2: saveCRTDFile
bool FrameFileIO::saveCRTDFile(QString filename, const QVector<CANFrame>* frames)
{
QFile *outFile = new QFile(filename);
int lineCounter = 0;
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
{
delete outFile;
return false;
}
//write in float format with 6 digits after the decimal point
outFile->write(QString::number(frames->at(0).timestamp / 1000000.0, 'f', 6).toUtf8() + tr(" CXX GVRET-PC Reverse Engineering Tool Output V").toUtf8() + QString::number(VERSION).toUtf8());
outFile->write("\n");
for (int c = 0; c < frames->count(); c++)
{
lineCounter++;
if (lineCounter > 100)
{
qApp->processEvents();
lineCounter = 0;
}
outFile->write(QString::number(frames->at(c).timestamp / 1000000.0, 'f', 6).toUtf8());
outFile->putChar(' ');
if (frames->at(c).extended)
{
outFile->write("R29 ");
}
else outFile->write("R11 ");
outFile->write(QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8());
outFile->putChar(' ');
for (int temp = 0; temp < frames->at(c).len; temp++)
{
outFile->write(QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8());
outFile->putChar(' ');
}
outFile->write("\n");
}
outFile->close();
delete outFile;
return true;
}
示例3: saveGenericCSVFile
//4f5,ff 34 23 45 24 e4
bool FrameFileIO::saveGenericCSVFile(QString filename, const QVector<CANFrame>* frames)
{
QFile *outFile = new QFile(filename);
int lineCounter = 0;
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
{
delete outFile;
return false;
}
outFile->write("ID,Data Bytes");
outFile->write("\n");
for (int c = 0; c < frames->count(); c++)
{
lineCounter++;
if (lineCounter > 100)
{
qApp->processEvents();
lineCounter = 0;
}
outFile->write(QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8());
outFile->putChar(44);
for (int temp = 0; temp < frames->at(c).len; temp++)
{
outFile->write(QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8());
outFile->putChar(' ');
}
outFile->write("\n");
}
outFile->close();
delete outFile;
return true;
}
示例4: saveFilters
void FramePlaybackWindow::saveFilters()
{
QString filename;
QFileDialog dialog(this);
QStringList filters;
filters.append(QString(tr("Filter list (*.ftl)")));
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilters(filters);
dialog.setViewMode(QFileDialog::Detail);
dialog.setAcceptMode(QFileDialog::AcceptSave);
if (dialog.exec() == QDialog::Accepted)
{
filename = dialog.selectedFiles()[0];
if (!filename.contains('.')) filename += ".ftl";
if (dialog.selectedNameFilter() == filters[0])
{
QFile *outFile = new QFile(filename);
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
return;
for (int c = 0; c < ui->listID->count(); c++)
{
outFile->write(QString::number(ui->listID->item(c)->text().toInt(NULL, 16), 16).toUtf8());
outFile->putChar(',');
if (ui->listID->item(c)->checkState() == Qt::Checked) outFile->putChar('T');
else outFile->putChar('F');
outFile->write("\n");
}
outFile->close();
}
}
}
示例5: saveMicrochipFile
/*
1247;RX;0xC2;8;0x5C;0x87;0x00;0x00;0x01;0x00;0x00;0x1C
1218;RX;0x236;1;0x00;0x00;0x00;0x00;0x00;0x00;0x00;0xF0
tokens:
0 = timestamp in ms
1 = direction (RX, TX)
2 = ID (in hex with 0x prefix)
3 = data length
4-x = data bytes in hex with 0x prefix
*/
bool FrameFileIO::saveMicrochipFile(QString filename, const QVector<CANFrame>* frames)
{
QFile *outFile = new QFile(filename);
QDateTime timestamp, tempStamp;
int lineCounter = 0;
timestamp = QDateTime::currentDateTime();
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
{
delete outFile;
return false;
}
outFile->write("//---------------------------------\n");
outFile->write("Microchip Technology Inc.\n");
outFile->write("CAN BUS Analyzer\n");
outFile->write("SavvyCAN Exporter\n");
outFile->write("Logging Started: ");
outFile->write(timestamp.toString("d/M/yyyy h:m:s").toUtf8());
outFile->write("\n");
outFile->write("//---------------------------------\n");
for (int c = 0; c < frames->count(); c++)
{
lineCounter++;
if (lineCounter > 100)
{
qApp->processEvents();
lineCounter = 0;
}
outFile->write(QString::number((int)(frames->at(c).timestamp / 1000)).toUtf8());
outFile->write(";RX;");
outFile->write("0x" + QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8() + ";");
outFile->write(QString::number(frames->at(c).len).toUtf8() + ";");
for (int temp = 0; temp < frames->at(c).len; temp++)
{
outFile->write("0x" + QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8());
outFile->putChar(';');
}
outFile->write("\n");
}
outFile->close();
delete outFile;
return true;
}
示例6: writeLayout
// ====================================================================================================================
// writeLayout(): The method to write the binary layout details to the given *open* file
// ====================================================================================================================
void MainWindow::writeLayout(QFile& file)
{
QByteArray geo_data = saveGeometry();
QByteArray layout_data = saveState();
bool ok = file.putChar((uchar)geo_data.size());
if (ok)
ok = file.write(geo_data) == geo_data.size();
if (ok)
ok = file.write(layout_data) == layout_data.size();
if (!ok)
{
QString msg = tr("Error writing to %1\n%2")
.arg(file.fileName())
.arg(file.errorString());
QMessageBox::warning(this, tr("Error"), msg);
return;
}
}
示例7: extractFile
/**OK
* Estrae il file fileName, contenuto nell'oggetto zip, con il nome fileDest.
* Se la funzione fallisce restituisce false e cancella il file che si è tentato di estrarre.
*
* La funzione fallisce se:
* * zip==NULL;
* * l'oggetto zip è stato aperto in una modalità non compatibile con l'estrazione di file;
* * non è possibile aprire il file all'interno dell'oggetto zip;
* * non è possibile creare il file estratto;
* * si è rilevato un errore nella copia dei dati (1);
* * non è stato possibile chiudere il file all'interno dell'oggetto zip (1);
*
* (1): prima di uscire dalla funzione cancella il file estratto.
*/
bool JlCompress::extractFile(QuaZip* zip, QString fileName, QString fileDest) {
// zip: oggetto dove aggiungere il file
// filename: nome del file reale
// fileincompress: nome del file all'interno del file compresso
// Controllo l'apertura dello zip
if (!zip) return false;
if (zip->getMode()!=QuaZip::mdUnzip) return false;
// Apro il file compresso
zip->setCurrentFile(fileName);
QuaZipFile inFile(zip);
if(!inFile.open(QIODevice::ReadOnly) || inFile.getZipError()!=UNZ_OK) return false;
// Controllo esistenza cartella file risultato
QDir().mkpath(QFileInfo(fileDest).absolutePath());
// Apro il file risultato
QFile outFile;
outFile.setFileName(fileDest);
if(!outFile.open(QIODevice::WriteOnly)) return false;
// Copio i dati
char c;
while(inFile.getChar(&c)) outFile.putChar(c);
if (inFile.getZipError()!=UNZ_OK) {
removeFile(QStringList(fileDest));
return false;
}
// Chiudo i file
inFile.close();
if (inFile.getZipError()!=UNZ_OK) {
removeFile(QStringList(fileDest));
return false;
}
outFile.close();
return true;
}
示例8: extract
bool QuaZipEx::extract(const QString & filePath, const QString & extDirPath, const QString & singleFileName)
{
QuaZip zip(filePath);
if (!zip.open(QuaZip::mdUnzip)) {
qWarning("testRead(): zip.open(): %d", zip.getZipError());
return false;
}
zip.setFileNameCodec("IBM866");
qWarning("%d entries\n", zip.getEntriesCount());
qWarning("Global comment: %s\n", zip.getComment().toLocal8Bit().constData());
QuaZipFileInfo info;
QuaZipFile file(&zip);
QFile out;
QString name;
char c;
for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) {
if (!zip.getCurrentFileInfo(&info)) {
qWarning("testRead(): getCurrentFileInfo(): %d\n", zip.getZipError());
return false;
}
if (!singleFileName.isEmpty())
if (!info.name.contains(singleFileName))
continue;
if (!file.open(QIODevice::ReadOnly)) {
qWarning("testRead(): file.open(): %d", file.getZipError());
return false;
}
name = QString("%1/%2").arg(extDirPath).arg(file.getActualFileName());
if (file.getZipError() != UNZ_OK) {
qWarning("testRead(): file.getFileName(): %d", file.getZipError());
return false;
}
//out.setFileName("out/" + name);
out.setFileName(name);
// this will fail if "name" contains subdirectories, but we don't mind that
out.open(QIODevice::WriteOnly);
// Slow like hell (on GNU/Linux at least), but it is not my fault.
// Not ZIP/UNZIP package's fault either.
// The slowest thing here is out.putChar(c).
while (file.getChar(&c)) out.putChar(c);
out.close();
if (file.getZipError() != UNZ_OK) {
qWarning("testRead(): file.getFileName(): %d", file.getZipError());
return false;
}
if (!file.atEnd()) {
qWarning("testRead(): read all but not EOF");
return false;
}
file.close();
if (file.getZipError() != UNZ_OK) {
qWarning("testRead(): file.close(): %d", file.getZipError());
return false;
}
}
zip.close();
if (zip.getZipError() != UNZ_OK) {
qWarning("testRead(): zip.close(): %d", zip.getZipError());
return false;
}
return true;
}
示例9: extractFileToDir
bool UBImportDocument::extractFileToDir(const QFile& pZipFile, const QString& pDir, QString& documentRoot)
{
QDir rootDir(pDir);
QuaZip zip(pZipFile.fileName());
if(!zip.open(QuaZip::mdUnzip))
{
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError();
return false;
}
zip.setFileNameCodec("UTF-8");
QuaZipFileInfo info;
QuaZipFile file(&zip);
QFile out;
char c;
documentRoot = UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(pDir);
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile())
{
if(!zip.getCurrentFileInfo(&info))
{
//TOD UB 4.3 O display error to user or use crash reporter
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError();
return false;
}
if(!file.open(QIODevice::ReadOnly))
{
qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError();
return false;
}
if(file.getZipError()!= UNZ_OK)
{
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError();
return false;
}
QString newFileName = documentRoot + "/" + file.getActualFileName();
QFileInfo newFileInfo(newFileName);
if (!rootDir.mkpath(newFileInfo.absolutePath()))
return false;
out.setFileName(newFileName);
if (!out.open(QIODevice::WriteOnly))
return false;
// Slow like hell (on GNU/Linux at least), but it is not my fault.
// Not ZIP/UNZIP package's fault either.
// The slowest thing here is out.putChar(c).
QByteArray outFileContent = file.readAll();
if (out.write(outFileContent) == -1)
{
qWarning() << "Import failed. Cause: Unable to write file";
out.close();
return false;
}
while(file.getChar(&c))
out.putChar(c);
out.close();
if(file.getZipError()!=UNZ_OK)
{
qWarning() << "Import failed. Cause: " << zip.getZipError();
return false;
}
if(!file.atEnd())
{
qWarning() << "Import failed. Cause: read all but not EOF";
return false;
}
file.close();
if(file.getZipError()!=UNZ_OK)
{
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError();
return false;
}
}
zip.close();
if(zip.getZipError()!=UNZ_OK)
{
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError();
return false;
}
return true;
}
示例10: unzipRead
bool QZip::unzipRead()
{
QuaZip zip(_zipFileName);
if(!zip.open(QuaZip::mdUnzip)) {
qWarning("File Can't be Open:%s",_zipFileName.toLocal8Bit().data());
return false;
}
zip.setFileNameCodec("IBM866");
printf("%d entries\n", zip.getEntriesCount());
printf("Global comment: %s\n", zip.getComment().toLocal8Bit().constData());
QuaZipFileInfo info;
printf("name\tcver\tnver\tflags\tmethod\tctime\tCRC\tcsize\tusize\tdisknum\tIA\tEA\tcomment\textra\n");
QuaZipFile file(&zip);
QFile out;
QString name;
char c;
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
if(!zip.getCurrentFileInfo(&info)) {
qWarning("testRead(): getCurrentFileInfo(): %d\n", zip.getZipError());
return false;
}
printf("%s\t%hu\t%hu\t%hu\t%hu\t%s\t%u\t%u\t%u\t%hu\t%hu\t%u\t%s\t%s\n",
info.name.toLocal8Bit().constData(),
info.versionCreated, info.versionNeeded, info.flags, info.method,
info.dateTime.toString(Qt::ISODate).toLocal8Bit().constData(),
info.crc, info.compressedSize, info.uncompressedSize, info.diskNumberStart,
info.internalAttr, info.externalAttr,
info.comment.toLocal8Bit().constData(), info.extra.constData());
if(!file.open(QIODevice::ReadOnly)) {
qWarning("testRead(): file.open(): %d", file.getZipError());
return false;
}
QStringList list;
if(info.name.contains("\\")){
list = info.name.split("\\");
}else if(info.name.contains("/")){
list = info.name.split("/");
}
QDir dir;
dir.setCurrent(_zipPathName);
QString tempDir = _zipPathName;
for(int ccc=0;ccc<list.count()-1;ccc++){
tempDir+="\\"+list.at(ccc);
if(!dir.exists(list.at(ccc))){
dir.mkdir(tempDir);
}
dir.setCurrent(tempDir);
}
name=file.getActualFileName();
if(file.getZipError()!=UNZ_OK) {
qWarning("testRead(): file.getFileName(): %d", file.getZipError());
return false;
}
out.setFileName(_zipPathName+"\\"+name);
// this will fail if "name" contains subdirectories, but we don't mind that
out.open(QIODevice::WriteOnly);
// Slow like hell (on GNU/Linux at least), but it is not my fault.
// Not ZIP/UNZIP package's fault either.
// The slowest thing here is out.putChar(c).
while(file.getChar(&c)) out.putChar(c);
out.close();
if(file.getZipError()!=UNZ_OK) {
qWarning("testRead(): file.getFileName(): %d", file.getZipError());
return false;
}
if(!file.atEnd()) {
qWarning("testRead(): read all but not EOF");
return false;
}
file.close();
if(file.getZipError()!=UNZ_OK) {
qWarning("testRead(): file.close(): %d", file.getZipError());
return false;
}
}
zip.close();
if(zip.getZipError()!=UNZ_OK) {
qWarning("testRead(): zip.close(): %d", zip.getZipError());
return false;
}
return true;
}
示例11: saveLogFile
bool FrameFileIO::saveLogFile(QString filename, const QVector<CANFrame>* frames)
{
QFile *outFile = new QFile(filename);
QDateTime timestamp, tempStamp;
int lineCounter = 0;
timestamp = QDateTime::currentDateTime();
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
{
delete outFile;
return false;
}
outFile->write("***BUSMASTER Ver 2.4.0***\n");
outFile->write("***PROTOCOL CAN***\n");
outFile->write("***NOTE: PLEASE DO NOT EDIT THIS DOCUMENT***\n");
outFile->write("***[START LOGGING SESSION]***\n");
outFile->write("***START DATE AND TIME ");
outFile->write(timestamp.toString("d:M:yyyy h:m:s:z").toUtf8());
outFile->write("***\n");
outFile->write("***HEX***\n");
outFile->write("***SYSTEM MODE***\n");
outFile->write("***START CHANNEL BAUD RATE***\n");
outFile->write("***CHANNEL 1 - Kvaser - Kvaser Leaf Light HS #0 (Channel 0), Serial Number- 0, Firmware- 0x00000037 0x00020000 - 500000 bps***\n");
outFile->write("***END CHANNEL BAUD RATE***\n");
outFile->write("***START DATABASE FILES (DBF/DBC)***\n");
outFile->write("***END OF DATABASE FILES (DBF/DBC)***\n");
outFile->write("***<Time><Tx/Rx><Channel><CAN ID><Type><DLC><DataBytes>***\n");
for (int c = 0; c < frames->count(); c++)
{
lineCounter++;
if (lineCounter > 100)
{
qApp->processEvents();
lineCounter = 0;
}
tempStamp = timestamp.addMSecs(frames->at(c).timestamp / 1000);
outFile->write(tempStamp.toString("h:m:s:z").toUtf8());
outFile->write(" Rx ");
outFile->write(QString::number(frames->at(c).bus).toUtf8() + " ");
outFile->write(QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8());
if (frames->at(c).extended) outFile->write(" x ");
else outFile->write(" s ");
outFile->write(QString::number(frames->at(c).len).toUtf8() + " ");
for (int temp = 0; temp < frames->at(c).len; temp++)
{
outFile->write(QString::number(frames->at(c).data[temp], 16).toUpper().rightJustified(2, '0').toUtf8());
outFile->putChar(' ');
}
outFile->write("\n");
}
outFile->close();
delete outFile;
return true;
}
示例12: addDataByte
void DataBlockFile::addDataByte(MidiByte byte)
{
prepareToWrite();
m_file.putChar(byte);
}