Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

bool QFile::open ( OpenMode  mode ) [virtual]

Opens the file using OpenMode mode, returning true if successful; otherwise false.

The mode must be QIODevice::ReadOnly, QIODevice::WriteOnly, or QIODevice::ReadWrite. It may also have additional flags, such as QIODevice::Text and QIODevice::Unbuffered.

Note:
In {QIODevice::}{WriteOnly} or {QIODevice::}{ReadWrite} mode, if the relevant file does not already exist, this function will try to create a new file before opening it.
Because of limitations in the native API, QFile ignores the Unbuffered flag on Windows.
See also:
QIODevice::OpenMode, setFileName()

Reimplemented from QIODevice.

Reimplemented in QTemporaryFile.

Definition at line 981 of file qfile.cpp.

References QAbstractFileEngine::error(), QIODevice::errorString(), fileEngine(), fileName(), QIODevice::isOpen(), seek(), size(), and unsetError().

Referenced by ClassWizard::accept(), SaveFormAsTemplate::accept(), QFontDatabase::addApplicationFont(), QGLContext::bindTexture(), CalculatorForm::CalculatorForm(), PatternistApplicationParser::convertToValue(), copy(), QTemporaryFile::createLocalFile(), QNetworkDiskCache::data(), PatternistApplicationParser::defaultValue(), QueryMainWindow::displayQuery(), QueryMainWindow::evaluate(), AddressBook::exportAsVCard(), QZipReader::extractAll(), QNetworkDiskCache::fileMetaData(), QSslCertificate::fromPath(), Tree::generateIndex(), QImageReader::imageFormat(), Window::insertTextObject(), Config::load(), QTranslator::load(), Q3Picture::load(), QPicture::load(), MainWindow::loadFile(), AddressBook::loadFromFile(), QueryMainWindow::loadInputFile(), QTextDocument::loadResource(), QTextBrowser::loadResource(), QScriptDebuggerConsolePrivate::loadScriptedCommands(), TextFinder::loadTextFile(), TextFinder::loadUiFile(), QHostInfo::localDomainName(), MainWindow::modelFromFile(), MainWindow::on_queryBox_currentIndexChanged(), QTemporaryFile::open(), open(), qdesigner_internal::DeviceProfileDialog::open(), MainWindow::openFile(), FindFileDialog::openFile(), Q3LocalFs::operationGet(), Q3LocalFs::operationPut(), QPictureIO::pictureFormat(), Q3TextStream::Q3TextStream(), QTextStream::QTextStream(), QZipReader::QZipReader(), QZipWriter::QZipWriter(), QPictureIO::read(), QHelpProjectData::readData(), AddressWidget::readFromFile(), Tree::readIndexFile(), rename(), Window::runScript(), QPicture::save(), Q3SVGPaintEngine::save(), MainWindow::saveFile(), AddressBook::saveToFile(), QSslSocket::setLocalCertificate(), QSslSocket::setPrivateKey(), QDesktopServices::storageLocation(), QPictureIO::write(), QSvgIconEngine::write(), and AddressWidget::writeToFile().

{
    Q_D(QFile);
    if (isOpen()) {
        qWarning("QFile::open: File (%s) already open", qPrintable(fileName()));
        return false;
    }
    if (mode & Append)
        mode |= WriteOnly;

    unsetError();
    if ((mode & (ReadOnly | WriteOnly)) == 0) {
        qWarning("QIODevice::open: File access not specified");
        return false;
    }
    if (fileEngine()->open(mode)) {
        QIODevice::open(mode);
        if (mode & Append)
            seek(size());
        return true;
    }
    QFile::FileError err = fileEngine()->error();
    if(err == QFile::UnspecifiedError)
        err = QFile::OpenError;
    d->setError(err, fileEngine()->errorString());
    return false;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index