当前位置: 首页>>代码示例>>C++>>正文


C++ QFile::deleteLater方法代码示例

本文整理汇总了C++中QFile::deleteLater方法的典型用法代码示例。如果您正苦于以下问题:C++ QFile::deleteLater方法的具体用法?C++ QFile::deleteLater怎么用?C++ QFile::deleteLater使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QFile的用法示例。


在下文中一共展示了QFile::deleteLater方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: install

bool tiBackupService::install(const QString &path)
{
    qDebug() << "tiBackupService::install()";

    QFile *tiServicePath = new QFile(path);
    if(!tiServicePath->open(QIODevice::WriteOnly | QIODevice::Text))
        return false;
    QTextStream out(tiServicePath);

    QFile *tiServiceTemplate = new QFile(":/init/tibackup");
    if(!tiServiceTemplate->open(QIODevice::ReadOnly | QIODevice::Text))
    {
        tiServicePath->close();
        tiServicePath->deleteLater();
        return false;
    }
    QTextStream in(tiServiceTemplate);

    out << in.readAll();
    out.flush();

    tiServicePath->setPermissions(QFile::ReadOwner | QFile::ExeOwner | QFile::ReadGroup | QFile::ExeGroup | QFile::ReadOther);
    tiServicePath->close();
    tiServiceTemplate->close();

    tiServicePath->deleteLater();
    tiServiceTemplate->deleteLater();

    emit serviceInstalled();
    return true;
}
开发者ID:theinvisible,项目名称:tiBackupLib,代码行数:31,代码来源:tibackupservice.cpp

示例2: saveApplicationState

void FacebookWidget::saveApplicationState() {
    QDir configDir = QDir::home();
    if(!configDir.cd(".config/Socializer")) {
        qDebug()<<"Making path "<<QDir::cleanPath(".config/Socializer");
        configDir.mkpath(QDir::cleanPath(".config/Socializer"));
        configDir.cd(".config/Socializer");
    }

    QFile *configFile = new QFile(configDir.absoluteFilePath("WindowState"));
    configFile->open(QIODevice::WriteOnly);
    QDataStream configFileDataStream(configFile);
    configFileDataStream << saveGeometry();
    configFileDataStream << windowSizeIndex;
    configFile->close();
    configFile->deleteLater();

    if(themeRefreshTimer->isActive()) {
        QFile *themeFile = new QFile(configDir.absoluteFilePath("ThemeState"));
        themeFile->open(QIODevice::WriteOnly);
        QDataStream themeFileDataStream(themeFile);
        themeFileDataStream << themeParams;
        themeFile->close();
        themeFile->deleteLater();
    } else {
        configDir.remove("ThemeState");
    }
}
开发者ID:spthaolt,项目名称:facebook,代码行数:27,代码来源:FacebookWidget.cpp

示例3: download

void HttpClient::download(const QString &destinationPath,
                          std::function<void (const QString &)> successHandler,
                          std::function<void (const QString &)> errorHandler) {
    bool  debug = d->debug;
    QFile *file = new QFile(destinationPath);

    if (file->open(QIODevice::WriteOnly)) {
        download([=](const QByteArray &data) {
            file->write(data);
        }, [=](const QString &) {
            // 请求结束后释放文件对象
            file->flush();
            file->close();
            file->deleteLater();

            if (debug) {
                qDebug().noquote() << QString("下载完成,保存到: %1").arg(destinationPath);
            }

            if (nullptr != successHandler) {
                successHandler(QString("下载完成,保存到: %1").arg(destinationPath));
            }
        }, errorHandler);
    } else {
        // 打开文件出错
        if (debug) {
            qDebug().noquote() << QString("打开文件出错: %1").arg(destinationPath);
        }

        if (nullptr != errorHandler) {
            errorHandler(QString("打开文件出错: %1").arg(destinationPath));
        }
    }
}
开发者ID:xtuer,项目名称:Qt,代码行数:34,代码来源:HttpClient.cpp

示例4: shutDown

 void shutDown()
 {
     disconnect(http, SIGNAL(finished()), q, SLOT(httpReqFinished()));
     http->deleteLater();
     http = 0;
     destination->close();
     destination->deleteLater();
     destination = 0;
     q->resetCheckSumData();
 }
开发者ID:olear,项目名称:qtifw,代码行数:10,代码来源:kdupdaterfiledownloader.cpp

示例5: shutDown

 void shutDown()
 {
     disconnect(http, &QNetworkReply::finished, q, &HttpDownloader::httpReqFinished);
     http->deleteLater();
     http = 0;
     destination->close();
     destination->deleteLater();
     destination = 0;
     q->resetCheckSumData();
 }
开发者ID:JustFFunny,项目名称:WorkSpace,代码行数:10,代码来源:filedownloader.cpp

示例6: upload

void ImgurUploader::upload(const QString &fileName)
{
    QFile *file = new QFile(fileName);

    if (!file->open(QIODevice::ReadOnly)) {
        emit error(ImageUploader::FileError, tr("Unable to read screenshot file"), fileName);
        file->deleteLater();
        return;
    }

    QNetworkRequest request(QUrl("https://api.imgur.com/3/image"));
    request.setRawHeader("Authorization", QString("Client-ID %1").arg(clientId()).toLatin1());

    QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

    if (!mSettings.value("anonymous", true).toBool()) {
        request.setRawHeader("Authorization", QByteArray("Bearer ") + mSettings.value("access_token").toByteArray());

        if (!mSettings.value("album").toString().isEmpty()) {
            QHttpPart albumPart;
            albumPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"album\""));
            albumPart.setBody(mSettings.value("album").toByteArray());
            multiPart->append(albumPart);
        }
    }

    QHttpPart imagePart;
    imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QMimeDatabase().mimeTypeForFile(fileName, QMimeDatabase::MatchExtension).name());
    imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\""));

    imagePart.setBodyDevice(file);
    file->setParent(multiPart);
    multiPart->append(imagePart);

    QNetworkReply *reply = Uploader::network()->post(request, multiPart);
    reply->setProperty("fileName", fileName);
    this->setProperty("fileName", fileName);
    multiPart->setParent(reply);

#ifdef Q_OS_WIN
    connect(reply, &QNetworkReply::sslErrors, [reply](const QList<QSslError> &errors) {
        Q_UNUSED(errors);
        if (QSysInfo::WindowsVersion <= QSysInfo::WV_2003) {
            reply->ignoreSslErrors();
        }
    });
#endif

    connect(reply, &QNetworkReply::uploadProgress, this, &ImgurUploader::uploadProgress);
    connect(this , &ImgurUploader::cancelRequest, reply, &QNetworkReply::abort);
    connect(this , &ImgurUploader::cancelRequest, reply, &QNetworkReply::deleteLater);

    connect(reply, &QNetworkReply::finished, this, &ImgurUploader::finished);
}
开发者ID:Neyoui,项目名称:Lightscreen,代码行数:54,代码来源:imguruploader.cpp

示例7: message_handler

//! debug message handler
void message_handler(QtMsgType type, const char *msg) {
    QMutexLocker lock(&message_handler_lock);
    QString fileName = QString("%0//%1").arg(QApplication::applicationDirPath()).arg("debug.log");
    QFile* logFile = new QFile(fileName);
    if (logFile->open(QIODevice::Append|QIODevice::Text|QIODevice::Unbuffered)) {
        QString m = QString(msg).trimmed();
        logFile->write(QString("%0\n").arg(m).toAscii());
        logFile->close();
    }
    logFile->deleteLater();
}
开发者ID:Jeff-Lewis,项目名称:quickanddirty,代码行数:12,代码来源:main.cpp

示例8: putFileFailed

void LocalDiskRepo::putFileFailed(QIODevice *device)
{
    qDebug() << "deleting a writable buffer - presumably a put file has failed";
    QFile* f;
    if (!device) {
        f = (QFile*) sender();
    } else {
        f = (QFile*) device;
    }

    f->remove();
    f->deleteLater();
}
开发者ID:robguthrie,项目名称:dudley,代码行数:13,代码来源:localdiskrepo.cpp

示例9: openFile

bool TextInfo::openFile(QString fileDir){
    QFile *file = new QFile(fileDir);

    if (file->open(QFile::ReadOnly | QFile::Text))
    {
        file->deleteLater();
        QByteArray buff = file->readAll();
        QTextStream stream( &buff );
        stream.setCodec("UTF-8");

        stream>>gameFormat;
        for (int i=1;i<=gameFormat;i++)
            for (int j=1;j<=gameFormat;j++)
                stream>>map[i][j];
    }else
开发者ID:ytl13508111107,项目名称:flowFree,代码行数:15,代码来源:textinfo.cpp

示例10: save

bool ComicStripFileResource::save(QString id, QByteArray data)
{
    QFile* file = new QFile();
    file->setFileName(path(id));

    bool openResult = file->open(QIODevice::WriteOnly);

    if (!openResult)
        return false;

    qint64 writeResult = file->write(data);

    file->close();
    file->deleteLater();

    return writeResult > 0;
}
开发者ID:Maledictus,项目名称:sailfishos-daily-comics,代码行数:17,代码来源:ComicStripFileResource.cpp

示例11: loadLevel

FlowFree::FlowFree(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::FlowFree) {
    ui->setupUi(this);

    QFile *file = new QFile(":/stylesheets/button.qss");
        file->open(QFile::ReadOnly);
        setStyleSheet(file->readAll());
        file->deleteLater();

    quint32 gameSize = GameModel::instance()->size();
    connect(this, SIGNAL(loadLevel(quint32)),
            ui->gameScene, SLOT(onLoadLevel(quint32)));

    connect(ui->lastLevelButton, &QPushButton::clicked,
    [=]() {
        emit loadLevel(--currentLevelId);
        ui->resultButton->setEnabled(false);
        ui->lastLevelButton->setEnabled(currentLevelId != 1);
        ui->nextLevelButton->setEnabled(currentLevelId != gameSize);
    });

    connect(ui->reloadButton, &QPushButton::clicked,
    [=]() {
        emit loadLevel(currentLevelId);
        ui->resultButton->setEnabled(false);
    });

    connect(ui->nextLevelButton, &QPushButton::clicked,
    [=]() {
        emit loadLevel(++currentLevelId);
        ui->resultButton->setEnabled(false);
        ui->lastLevelButton->setEnabled(currentLevelId != 1);
        ui->nextLevelButton->setEnabled(currentLevelId != gameSize);
    });

    connect(ui->resultButton, &QPushButton::clicked,
            ui->gameScene, &GameScene::autoSolve);

    connect(ui->resultButton, &QPushButton::clicked,
    [=]() {
        ui->resultButton->setEnabled(false);
    });

    connect(ui->gameScene, &GameScene::nextLevel,
    [=]() {
        ui->nextLevelButton->click();
    });

    connect(ui->soundCheckBox, &QCheckBox::stateChanged,
            ui->gameScene, &GameScene::setSound);

    connect(ui->gameScene, SIGNAL(timeChanged(int)),
            ui->lcdNumber, SLOT(display(int)));

    connect(ui->gameScene, &GameScene::enableResultButton,
    [=]() {
        ui->resultButton->setEnabled(true);
    });

    currentLevelId = 0;
    ui->nextLevelButton->click();
}
开发者ID:TennyZhuang,项目名称:Flow-Free-desktop,代码行数:63,代码来源:flowfree.cpp

示例12: main

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    // 在代码块里执行网络访问,是为了测试 HttpClient 对象在被析构后,网络访问的回调函数仍然能正常执行
    {
        QString url("http://localhost:8080/rest");

        // [[1]] GET 请求无参数
        HttpClient(url).get([](const QString &response) {
            qDebug().noquote() << response;
        });

        // [[2]] GET 请求有参数,有自定义 header
        HttpClient(url).debug(true).param("name", "诸葛亮").header("token", "md5sum").get([](const QString &response) {
            qDebug().noquote() << response;
        });
        // 提示: 多个参数也可以传入 map: HttpClient(url).params({{"name", "诸葛亮"}, {"attackDamage", "99"}}).get(...);

        // [[3]] POST 请求,使用 param 添加参数,请求的参数使用 Form 格式
        HttpClient(url).debug(true).param("name", "卧龙")
                .post([](const QString &response) {
            qDebug().noquote() << response;
        });

        // [[4]] PUT 请求,使用 json 添加参数,请求的参数使用 Json 格式
        HttpClient(url).debug(true).json("{\"name\": \"孔明\"}").put([](const QString &response) {
            qDebug().noquote() << response;
        });

        // [[5]] DELETE 请求
        HttpClient(url).debug(true).remove([](const QString &response) {
            qDebug().noquote() << response;
        });
    }

    {
        // [[6]] 下载: 直接保存到文件
        HttpClient("http://xtuer.github.io/img/dog.png").debug(true).download("/Users/Biao/Desktop/dog-1.png");

        // [[7]] 下载: 自己处理下载得到的字节数据
        QFile *file = new QFile("/Users/Biao/Desktop/dog-2.png");
        if (file->open(QIODevice::WriteOnly)) {
            HttpClient("http://xtuer.github.io/img/dog.png").debug(true).download([=](const QByteArray &data) {
                file->write(data);
            }, [=](const QString &) {
                file->flush();
                file->close();
                file->deleteLater();

                qDebug().noquote() << "下载完成";
            });
        } else {
            file->deleteLater();
            file = nullptr;
        }
    }

    {
        // [[8]] 上传文件
        HttpClient("http://localhost:8080/upload").debug(true).upload(QString("/Users/Biao/Pictures/ade.jpg"));

        // [[9]] 上传文件: 也能同时传参数
        HttpClient("http://localhost:8080/upload").debug(true)
                .param("username", "Alice").param("password", "Passw0rd")
                .upload(QString("/Users/Biao/Pictures/ade.jpg"));

        // [[10]] 上传数据: 例如使用摄像头拍照后直接把图片数据传到服务器
        QFile dataFile("/Users/Biao/Pictures/ade.jpg");
        dataFile.open(QIODevice::ReadOnly);
        QByteArray data = dataFile.readAll();
        HttpClient("http://localhost:8080/upload").debug(true).upload(data);

        // [[11]] 上传多个文件文件
        QStringList paths;
        paths << "/Users/Biao/Desktop/photo.jpg" << "/Users/Biao/Desktop/project.numbers";
        HttpClient("http://localhost:8080/uploads").debug(true).upload(paths);
    }

    {
        // [[12]] 共享 QNetworkAccessManager
        // 每创建一个 QNetworkAccessManager 对象都会创建一个线程,当频繁的访问网络时,为了节省线程资源,调用 manager()
        // 使用共享的 QNetworkAccessManager,它不会被 HttpClient 删除,需要我们自己不用的时候删除它。
        // 如果下面的代码不传入 QNetworkAccessManager,从任务管理器里可以看到创建了几千个线程。
        QNetworkAccessManager *manager = new QNetworkAccessManager();
        for (int i = 0; i < 5000; ++i) {
            HttpClient("http://localhost:8080/rest").manager(manager).get([=](const QString &response) {
                qDebug().noquote() << response << ", " << i;
            });
        }
    }

    return a.exec();
}
开发者ID:xtuer,项目名称:Qt,代码行数:93,代码来源:main.cpp


注:本文中的QFile::deleteLater方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。