本文整理汇总了C++中QFile::fileName方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::fileName方法的具体用法?C++ QFile::fileName怎么用?C++ QFile::fileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFile
的用法示例。
在下文中一共展示了QFile::fileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: raiseError
static void raiseError(QXmlStreamReader &reader, const QString &error, Settings::ParseMode parseMode)
{
if (parseMode == Settings::StrictParseMode) {
reader.raiseError(error);
} else {
QFile *xmlFile = qobject_cast<QFile*>(reader.device());
if (xmlFile) {
qWarning().noquote().nospace()
<< "Ignoring following settings reader error in " << xmlFile->fileName()
<< ", line " << reader.lineNumber() << ", column " << reader.columnNumber()
<< ": " << error;
} else {
qWarning("Ignoring following settings reader error: %s", qPrintable(error));
}
}
}
示例2: findScript
static QString findScript(const QString& jsFilePath, const QString& libraryPath)
{
if (!jsFilePath.isEmpty()) {
QFile jsFile;
// Is file in the PWD?
jsFile.setFileName(QDir::fromNativeSeparators(jsFilePath)); //< Normalise User-provided path
if (!jsFile.exists()) {
// File is not in the PWD. Is it in the lookup directory?
jsFile.setFileName(libraryPath + '/' + QDir::fromNativeSeparators(jsFilePath));
}
return jsFile.fileName();
}
return QString();
}
示例3: slotUnsetImage
void ThumbnailPicker::slotUnsetImage() {
QFile file;
if ( KSUtils::openDataFile( file, "noimage.png" ) ) {
file.close();
Image->load( file.fileName(), "PNG" );
} else {
*Image = Image->scaled( dd->thumbnail()->width(), dd->thumbnail()->height() );
Image->fill( dd->palette().color( QPalette::Window ) );
}
ui->EditButton->setEnabled( false );
ui->CurrentImage->setPixmap( *Image );
ui->CurrentImage->update();
bImageFound = false;
}
示例4: Export
bool PNGAImageWriter::Export(QFile& file) {
QImage pixmap = buildImage();
assert(pixmap.isGrayscale());
png::image<png::gray_pixel> image(pixmap.width(), pixmap.height());
for (size_t y = 0; y < image.get_height(); ++y)
{
for (size_t x = 0; x < image.get_width(); ++x)
{
QRgb pix = pixmap.pixel(x, y);
assert(qIsGray(pix));
image[y][x] = png::gray_pixel(qAlpha(pix));
}
}
image.write(file.fileName().toStdString());
return true;
}
示例5: downloadFile
bool ftpInterface::downloadFile(QString sourceFileName,QString destinationFilename)
{
delSrc=FALSE;
aborting=FALSE;
addToLog("FTP downloadFile",LOGFTP);
QFile *destFn;
destFn=new QFile(destinationFilename);
if(!destFn->open(QIODevice::WriteOnly))
{
addToLog(QString("FTP unable to open destinationFilename %1").arg(destinationFilename),LOGFTP);
return FALSE;
}
if (sourceFileName.isNull() ) return FALSE;
ftpDone=TRUE;
if(isUnconnected())
{
ftpDone=FALSE;
connectToHost();
}
while(!ftpDone)
{
if(aborting) return FALSE;
qApp->processEvents();
}
if(isUnconnected())
{
addToLog("FTP connection failed",LOGFTP);
return FALSE;
}
ftpDone=FALSE;
ftpCommandSuccess=FALSE;
ftp->get( sourceFileName, destFn,QFtp::Binary);
addToLog(QString("FTP get sourcefile %1 destination %2").arg(sourceFileName).arg(destFn->fileName()),LOGFTP);
while(!ftpDone)
{
if(aborting) return FALSE;
qApp->processEvents();
}
if(!ftpCommandSuccess) return FALSE;
addToLog(QString("FTP file: %1 bytes: %2").arg(destinationFilename).arg(QFile(destinationFilename).size()),LOGFTP);
return TRUE;
}
示例6: fi
static qint64 open_file(QFile & fp, BooL & ro)
{
QString filename = fp.fileName();
while (! fp.open(QIODevice::ReadOnly)) {
if (QMessageBox::critical(0, "Uml",
filename + "\ncannot be opened for read, retry ?\n",
"yes", "no", 0, 0, 0) != 0)
return -1;
}
QFileInfo fi(fp);
ro = !fi.isWritable();
return fi.size();
}
示例7: updateWidgetFromXMLDocument
/**
* Updates the widget from a xml document (of a test)
* @param root
*/
void NMGNetperfXMLInterpret::updateWidgetFromXMLDocument ( const QString & fileName )
{
widget->txtTestName->setText ( "" );
widget->txtTestId->setText ( "" );
QString testType = "";
NMGMetaData * metadata = new NMGMetaData();
QFile file ( fileName );
if ( !file.open ( QFile::ReadOnly | QFile::Text ) )
cerr << "File " << qPrintable( fileName ) << " couldn't be read";
else
{
NMGMetaDataParser metaParser ( *metadata );
if ( !metaParser.read ( &file ) )
cerr << "Parse error reading metadata in file " << qPrintable ( file.fileName() ) << ":\n" << qPrintable( metaParser.errorString() );
else
{
testType = metadata->getTypeOfTest().toLower();
//Backward compatibility with older test files that doesn't have <type> tag
if ( testType.isEmpty() )
{
if ( metadata->isSetUncommonElement ( TAG_CONF_NETPERF ) ) metadata->setTypeOfTest ( TYPE_TPUT );
testType = metadata->getTypeOfTest().toLower();
}
}
}
if ( testType == TYPE_TPUT )
{
widget->txtTestName->setText ( metadata->getTestName() );
widget->txtTestId->setText ( metadata->getTestIdentifier() );
//TODO result Path?
//updateWidgetFromXMLNodeSource ( elem );
NMGHostInformationComboWidget * combo = widget->hostSourceCombo;
combo->setAddressOfStation ( metadata->getSourceAddress() );
//updateWidgetFromXMLNodeDestination ( elem );
combo = widget->hostDestinationCombo;
combo->setAddressOfStation ( metadata->getDestinationAddress() );
updateWidgetFromXMLNodeConfNetperf ( metadata->getUncommonElement ( TAG_CONF_NETPERF ) );
delete metadata;
}
}
示例8: on_openIncoming_clicked
void MainWindow::on_openIncoming_clicked()
{
if (ClientReceiveSetup() == 0)
{
QFile *file = new QFile(QFileDialog::getSaveFileName(this, tr("Save song as"), 0, tr("Music (*.wav)")));
if (file->fileName() != NULL)
{
ui->openIncoming->setEnabled(false);
ui->disconnectIncoming->setEnabled(true);
file->open(QIODevice::WriteOnly);
ClientListen((HANDLE) _get_osfhandle(file->handle()));
} else
{
ClientCleanup();
}
}
}
示例9: saveScreenshot
void PhoneInfoWidget::saveScreenshot()
{
QFile plik;
plik.setFileName(QFileDialog::getSaveFileName(this, tr("Save File..."), "./screenshot.png", tr("Png file")+" (*.png)"));
if (plik.fileName().isEmpty())
return;
if (plik.open(QFile::WriteOnly))
{
QMatrix matrix;
matrix.rotate(this->rotation);
QImage image;
image = this->screenshot.toImage();
image = image.transformed(matrix);
image.save(&plik, "PNG");
plik.close();
}
}
示例10: StoreAvatar
/** The clients are free to not call this function if they know the avatar is
* already stored. That means that we should be beware of this when implementing
* caching, if we'd ever do.
*
* See EntryBase::SetVCard() for example.
*/
void AvatarsStorage::StoreAvatar (const QImage& image, const QByteArray& hash)
{
QFile file (AvatarsDir_.absoluteFilePath (hash));
if (file.exists () && file.size ())
return;
if (!file.open (QIODevice::WriteOnly | QIODevice::Truncate))
{
qWarning () << Q_FUNC_INFO
<< "unable to open file"
<< file.fileName ()
<< "for writing";
return;
}
image.save (&file, "PNG", 100);
}
示例11: errorHandling
void MetaInfoParser::errorHandling(QXmlStreamReader &reader, QFile &file)
{
if (!reader.hasError())
return;
qDebug() << QString("Error at %1, %2:%3: %4")
.arg(file.fileName())
.arg(reader.lineNumber())
.arg(reader.columnNumber())
.arg(reader.errorString());
file.reset();
QString fileString = file.readAll();
QString snippetString;
int lineCount = 0;
int position = reader.characterOffset();
while (position >= 0)
{
if (fileString[position] == '\n') {
if (lineCount > 3)
break;
lineCount++;
}
snippetString.prepend(fileString[position]);
position--;
}
lineCount = 0;
position = reader.characterOffset();
while (position >= 0)
{
position++;
if (fileString[position] == '\n') {
if (lineCount > 1)
break;
lineCount++;
}
snippetString.append(fileString[position]);
}
qDebug() << snippetString;
}
示例12: initHandler
/*!
\internal
*/
bool QImageReaderPrivate::initHandler()
{
// check some preconditions
if (!device || (!deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly))) {
imageReaderError = QImageReader::DeviceError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Invalid device"));
return false;
}
// probe the file extension
if (deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly) && autoDetectImageFormat) {
QList<QByteArray> extensions = QImageReader::supportedImageFormats();
if (!format.isEmpty()) {
// Try the most probable extension first
int currentFormatIndex = extensions.indexOf(format.toLower());
if (currentFormatIndex > 0)
extensions.swap(0, currentFormatIndex);
}
int currentExtension = 0;
QFile *file = static_cast<QFile *>(device);
QString fileName = file->fileName();
do {
file->setFileName(fileName + QLatin1Char('.')
+ QString::fromLatin1(extensions.at(currentExtension++).constData()));
file->open(QIODevice::ReadOnly);
} while (!file->isOpen() && currentExtension < extensions.size());
if (!device->isOpen()) {
imageReaderError = QImageReader::FileNotFoundError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "File not found"));
file->setFileName(fileName); // restore the old file name
return false;
}
}
// assign a handler
if (!handler && (handler = createReadHandlerHelper(device, format, autoDetectImageFormat, ignoresFormatAndExtension)) == 0) {
imageReaderError = QImageReader::UnsupportedFormatError;
errorString = QLatin1String(QT_TRANSLATE_NOOP(QImageReader, "Unsupported image format"));
return false;
}
return true;
}
示例13: Exception
TrackList::TrackList(QFile &input)
{
if (!input.exists()) {
throw new Exception(QString("File not found: <%1>").arg(input.fileName()));
}
QDomDocument d;
d.setContent(&input);
QDomElement root = d.documentElement();
QDomElement pointNode, segmentNode, trackNode;
Track t;
// <gpx
// <trk><name>АВГ-30-09 14:15:47</name>
// <trkseg>
// <trkpt lat="54.11111" lon="37.11111"><ele>112.13</ele><time>2009-08-29T15:36:42Z</time></trkpt>
tracks.clear();
trackNode = root.firstChildElement("trk");
for (; !trackNode.isNull(); trackNode = trackNode.nextSiblingElement("trk")) {
t.name = trackNode.firstChildElement("name").text();
segmentNode = trackNode.firstChildElement("trkseg");
for (; !segmentNode.isNull(); segmentNode = segmentNode.nextSiblingElement("trkseg")) {
t.points.clear();
pointNode = segmentNode.firstChildElement("trkpt");
for (; !pointNode.isNull(); pointNode = pointNode.nextSiblingElement("trkpt")) {
t.points.append(TrackPoint(
pointNode.attribute("lat").toFloat(),
pointNode.attribute("lon").toFloat(),
QDateTime::fromString(pointNode.firstChildElement("time").text(), Qt::ISODate)
));
}
qSort(t.points);
if (t.points.length()) {
tracks.append(t);
}
}
}
}
示例14: saveData
void MainWindow::saveData(DecodeChannel *decode, const char *err)
{
QByteArray &buf = decode->buf;
QFile *file = decode->file;
if (buf.size() > 0) {
QDate date = QDate::currentDate();
QTime time = QTime::currentTime();
if (file->isOpen()) {
if (file->size() > (64 * 1024 * 1024))
file->close();
QStringList gzipArgs;
gzipArgs << "-1";
gzipArgs << file->fileName();
QProcess::startDetached("gzip", gzipArgs);
}
if (!file->isOpen()) {
QString suffix("-");
suffix += date.toString("MMdd");
suffix += time.toString("-hhmmss");
QString filename = QString(decode->basename).arg(suffix);
file->setFileName(filename);
file->open(QIODevice::WriteOnly | QIODevice::Truncate);
}
QString prefix;
prefix += date.toString("MM/dd-");
prefix += time.toString("hh:mm:ss (");
if (err)
prefix += err;
prefix += ") >>> ";
QByteArray stream;
stream.reserve(4096);
stream.append(prefix);
char str[4];
for (int i = 0; i < buf.size(); i++) {
qsnprintf(str, 4, "%02x ", (unsigned char)buf.at(i));
stream.append(str, 3);
}
stream.append('\n');
file->write(stream);
}
}
示例15: compress
bool KTPackageHandler::compress(QuaZip *zip, const QString &path)
{
QFile inFile;
QuaZipFile outFile(zip);
char c;
QFileInfoList files= QDir(path).entryInfoList();
foreach(QFileInfo file, files)
{
QString filePath = path+"/"+file.fileName();
if ( file.fileName().startsWith(".") ) continue;
if ( file.isDir() )
{
compress(zip, file.path()+"/"+file.fileName());
continue;
}
inFile.setFileName(filePath);
if(!inFile.open(QIODevice::ReadOnly))
{
dError() << "Error opening file " << inFile.fileName() << " : " << inFile.errorString();
return false;
}
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(stripRepositoryFromPath(filePath), stripRepositoryFromPath(filePath) )))
{
return false;
}
while(inFile.getChar(&c) && outFile.putChar(c));
if(outFile.getZipError()!=UNZ_OK)
{
return false;
}
outFile.close();
if(outFile.getZipError()!=UNZ_OK)
{
return false;
}
inFile.close();
}